[MUSIC PLAYING]
MARTIN OMANDER: Hey, Ahmet.
AHMET ALP BALKAN: Hi, Martin.
What's going on?
MARTIN OMANDER: I built a Cloud Run service,
and I noticed it's slower for users in Australia
than for users in the US.
Could you help me fix that?
AHMET ALP BALKAN: Sounds like you
might need to put your Cloud Run services closer to your users.
I can show you how.
[MUSIC PLAYING]
MARTIN OMANDER: OK.
My web application has a sign-up form with a city field.
As the user types into the city field,
they will get autocomplete suggestions
from a Cloud Run service.
AHMET ALP BALKAN: That sounds good, Martin.
MARTIN OMANDER: And I deployed the service
to the us-central1 region.
When I access it from my house here in California,
I get response times between 70 and 80 milliseconds.
I'm pretty happy with that.
AHMET ALP BALKAN: But you're saying this service is
slower for users in Australia?
MARTIN OMANDER: Yeah.
This is what happens when I access
the service from a virtual machine I set up in Sydney.
There.
You see here, the responses are much slower--
just over 200 milliseconds.
Why is that happening, Ahmet?
AHMET ALP BALKAN: Right now, your Cloud Run service
is running in us-central1, which is in the Iowa data center.
People in Australia are so much further away from Iowa
than you are, so naturally their requests will take longer.
For many applications, this is not a big deal.
If the response times you just showed me are acceptable,
you can keep serving all your users from one location.
But for some interactive services,
like your autocomplete service, every millisecond counts.
So your users in Australia would see a better performance
if you could take this autocomplete service closer
to them.
This means you need to deploy the same Cloud Run
service to a Google data center in Australia.
MARTIN OMANDER: OK.
That sounds great.
But how do I configure my Cloud Run service
so I can route them to the nearest Google data center?
AHMET ALP BALKAN: You don't have to.
The Google Cloud HTTPS Load Balancer
lets you use global anycast IPs, meaning wherever
the user connects from, they're routed to the nearest
Google data center, and then the Cloud Load Balancer will route
the request to the nearest Cloud Run service
that you have deployed.
MARTIN OMANDER: OK.
Let's do it.
But I'm an application developer, not a network admin.
Are there any instructions for this?
AHMET ALP BALKAN: Yes.
I just sent you the link to a web page
that describes the process.
Basically, you have to set up an IP address,
a TLS certificate, then tie it all together
by creating a load balancer.
MARTIN OMANDER: OK.
Let's see-- pulling it up here.
It looks like it's just a list of gcloud commands.
Looks like I can enter the names of my services,
copy the commands, and then I just run these in my terminal?
AHMET ALP BALKAN: Yeah, that's right.
Also, you need to update the DNS records for your domain name
from your registrar to send the traffic to the IP address
that you just created.
It's all in the instructions.
MARTIN OMANDER: Cool.
I will run these gcloud commands and update the DNS record.
It can take a while for DNS to propagate.
See you back here in 30 minutes?
AHMET ALP BALKAN: Sounds good.
MARTIN OMANDER: All right.
We're back.
What now?
AHMET ALP BALKAN: Let's first make
sure that you haven't broken anything for your users
in the US.
Do you want to make a request?
MARTIN OMANDER: Ah, yes.
Let's see.
Trying it out now from here in California.
Ah.
There.
OK, good.
It's still working, and it's still fast.
AHMET ALP BALKAN: Excellent.
Now, let's check if the response time has improved
for your users in Australia.
MARTIN OMANDER: OK.
Pulling up the web page now.
Entering the first letter of a city name.
Yeah, that's a lot faster.
Before, it was over 200 milliseconds.
Now, most of these requests took less than 20.
And it shows here that it's serving from a data
center in Australia.
But why is Sydney faster than what I get from my house
here in California?
AHMET ALP BALKAN: Good question.
This is because the nearest deployment
that you have right now is in us-central1,
which is in Iowa data center.
You could deploy this to us-west2,
which is in the Los Angeles data center,
to get even better response times from your home.
In fact, there are no downsides to deploying
all available regions, because you pay a fixed
price for the load balancer.
And since Cloud Run charges you based on the requests,
there is no downside to deploying your application
everywhere.
MARTIN OMANDER: All right.
So my current deployment is working well
for users in the US and in Australia right now.
But what happens if a user is in another place-- let's
say Singapore?
I haven't deployed my Cloud Run service there.
AHMET ALP BALKAN: Google's load balancer
is smart enough to route them to the closest Cloud Run service
that you have deployed behind the load balancer.
Why don't you try it?
MARTIN OMANDER: OK.
I set up a virtual machine here in Singapore.
Let's see.
Opening the web page.
Oh, looks like they get just over 100 milliseconds' response
time.
And here-- we can see the data was served from the Cloud Run
service in Sydney.
AHMET ALP BALKAN: Nice.
And if you don't want to run a lot of gcloud commands
to deploy this application manually,
you can write a Terraform module and easily
deploy your application to all regions.
We'll put a link in the description for that.
MARTIN OMANDER: Oh, cool.
But, Ahmet, what about my users in Antarctica?
AHMET ALP BALKAN: Ah, serious question.
Do you mean the researchers and the penguins?
Maybe we'll get to it someday.
MARTIN OMANDER: Ah, yes, the penguins.
Everyone, thank you so much for watching.
Please leave the comments below and let
us know if there are any other topics you'd
like us to discuss.
[MUSIC PLAYING]