Reputation: 106
Today I have the same API code deployed to four different functions in Firebase's Cloud Functions:
Function | Region |
---|---|
api_us_central | us-central1 |
api_us_east | us-east1 |
api_europe | europe-west1 |
api_asia | asia-east2 |
And then I have a custom domain my-api.domain.com which is associated with my Firebase's project.
That said, I'm looking for a way to direct any API requests to the closest function available (geographically).
The first thought that crossed my mind was to set up my-api.domain.com DNS via Constellix GTD with different records pointing to each function. However it seems they only support A records, and also I wasn't able to find out a way to change the rewrites to different functions in firebase.json
file dynamically.
Do you guys have any advice on how I could proceed here?
Thanks in advance!
Upvotes: 2
Views: 229
Reputation: 1524
You might want to take a look into the GCP LBs. In Global HTTP(S) Load Balancing and CDN now support serverless compute you can find an article that talk about this:
-Multi-region availability for Cloud Run and Cloud Functions
By integrating our serverless offerings with HTTP(S) Load Balancer, you can now deploy Cloud Run and Cloud Functions services in multiple regions. Using Cloud Run as an example, a load balancer configured with a Premium Network Service Tier and a single forwarding rule, will deliver the request to the backend Cloud Run service closest to your clients. Processing requests from multiple regions helps improve your service’s availability as well as response latency to your clients. Requests land in the region closest to your users, however if the region is unavailable or short on capacity, the request will be routed to a different region.
Enabling this capability is as simple as deploying Cloud Run services to different regions, setting up multiple serverless NEGs and connecting the load balancer to global backend services.
Here you will find more details about Configuring Standard Tier for HTTP(S) and TCP/SSL Proxy Load Balancing.
I recommend to first test this into a proof of concept to avoid impact your prod environments.
Image taken from the doc aforementioned.
Upvotes: 2