Stay organized with collections
Save and categorize content based on your preferences.
Configure data locality with locational endpoints
This page describes how to configure the Firestore client libraries
to use a locational endpoint.
When you use Firestore client libraries, you can use either of the following endpoints:
Global endpoint: By default, the Firestore client libraries send API requests to a global
service endpoint named firestore.googleapis.com. The global service endpoint
routes the request to your database. During routing, a request
might pass through a locational service endpoint in a location that's different
from your database location.
Locational endpoint: A locational endpoint enforces regional restrictions, ensuring that data is stored and processed in a specified region.
To guarantee that the service endpoint processes your app's Firestore
requests in the same region as your database, specify a locational endpoint
in the client library.
Set a locational endpoint
The following examples show how to set a locational endpoint when you initialize a
Firestore client. Setting a locational endpoint other than where your data
resides might result in a PermissionDeniedError error.
importcom.google.auth.oauth2.GoogleCredentials;importcom.google.cloud.firestore.Firestore;importcom.google.cloud.firestore.FirestoreOptions;/** * Demonstrate how to set a regional endpoint. */publicclassRegionalEndpointSnippets{/** * Create a client with a regional endpoint. **/publicFirestoreregionalEndpoint(StringprojectId,Stringendpoint)throwsException{FirestoreOptionsfirestoreOptions=FirestoreOptions.newBuilder().setProjectId(projectId).setCredentials(GoogleCredentials.getApplicationDefault())// set endpoint like nam5-firestore.googleapis.com:443.setHost(endpoint).build();FirestoredbWithEndpoint=firestoreOptions.getService();returndbWithEndpoint;}}
Firestore supports locational endpoints for both region and multi-region locations.
Use the following format to define locational endpoints:
Java
REGION_NAME-firestore.googleapis.com:443
Make sure that the port number is defined along with the endpoint.
Python
REGION_NAME-firestore.googleapis.com
Go
REGION_NAME-firestore.googleapis.com:443
Make sure that the port number is defined along with the endpoint.
Replace REGION_NAME with the name of a regional or multi-regional hostnames.
Some examples of hostnames are:
eur3-firestore.googleapis.com
nam5-firestore.googleapis.com
europe-west6-firestore.googleapis.com
asia-northeast2-firestore.googleapis.com
For a complete list of multi-regional and regional hostnames, see Firestore locations.
Restrict global API endpoint usage
To help enforce the use of regional endpoints, use the
constraints/gcp.restrictEndpointUsage organization policy constraint to block
requests to the global API endpoint. For more information, see
Restricting endpoint usage.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[],[],null,["Configure data locality with locational endpoints\n\nThis page describes how to configure the Firestore client libraries\nto use a locational endpoint.\n\nWhen you use Firestore client libraries, you can use either of the following endpoints:\n\n- **Global endpoint** : By default, the Firestore client libraries send API requests to a global\n service endpoint named `firestore.googleapis.com`. The global service endpoint\n routes the request to your database. During routing, a request\n might pass through a locational service endpoint in a location that's different\n from your database location.\n\n- **Locational endpoint** : A locational endpoint enforces regional restrictions, ensuring that data is stored and processed in a specified region.\n To guarantee that the service endpoint processes your app's Firestore\n requests in the same region as your database, specify a *locational endpoint*\n in the client library.\n\nSet a locational endpoint\n\nThe following examples show how to set a locational endpoint when you initialize a\nFirestore client. Setting a locational endpoint other than where your data\nresides might result in a `PermissionDeniedError` error.\n**Note:** You can set locational endpoints in the server client libraries, namely C#, Go, Java, Node.js, PHP, Python, and Ruby. The mobile and web SDKs, namely, Android, IOS, and Web are not supported. \n\nJava\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.auth.oauth2.https://cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.html;\n import com.google.cloud.firestore.https://cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.Firestore.html;\n import com.google.cloud.firestore.https://cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.FirestoreOptions.html;\n\n\n /**\n * Demonstrate how to set a regional endpoint.\n */\n public class RegionalEndpointSnippets {\n\n /**\n * Create a client with a regional endpoint.\n **/\n public https://cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.Firestore.html regionalEndpoint(String projectId, String endpoint) throws Exception {\n https://cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.FirestoreOptions.html firestoreOptions =\n https://cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.FirestoreOptions.html.newBuilder()\n .setProjectId(projectId)\n .setCredentials(https://cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.html.https://cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.html#com_google_auth_oauth2_GoogleCredentials_getApplicationDefault__())\n // set endpoint like nam5-firestore.googleapis.com:443\n .setHost(endpoint)\n .build();\n https://cloud.google.com/java/docs/reference/google-cloud-firestore/latest/com.google.cloud.firestore.Firestore.html dbWithEndpoint = firestoreOptions.getService();\n\n return dbWithEndpoint;\n }\n\n }\n\nPython\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n ENDPOINT = \"nam5-firestore.googleapis.com\"\n client_options = ClientOptions(api_endpoint=ENDPOINT)\n db = firestore.Client(client_options=client_options)\n\n cities_query = db.collection(\"cities\").limit(2).get()\n for r in cities_query:\n print(r)\n\n\u003cbr /\u003e\n\nLocational endpoint semantics\n\nFirestore supports locational endpoints for both region and multi-region locations.\n\nUse the following format to define locational endpoints: \n\nJava \n\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION_NAME\u003c/span\u003e\u003c/var\u003e-firestore.googleapis.com:443\n\nMake sure that the port number is defined along with the endpoint.\n\nPython \n\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION_NAME\u003c/span\u003e\u003c/var\u003e-firestore.googleapis.com\n\nGo \n\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nx\"\u003eREGION_NAME\u003c/span\u003e\u003c/var\u003e-firestore.googleapis.com:443\n\nMake sure that the port number is defined along with the endpoint.\n\nReplace \u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e with the name of a regional or multi-regional hostnames.\n\nSome examples of hostnames are:\n\n- `eur3-firestore.googleapis.com`\n- `nam5-firestore.googleapis.com`\n- `europe-west6-firestore.googleapis.com`\n- `asia-northeast2-firestore.googleapis.com`\n\nFor a complete list of multi-regional and regional hostnames, see [Firestore locations](/firestore/docs/locations).\n\nRestrict global API endpoint usage\n\nTo help enforce the use of regional endpoints, use the\n`constraints/gcp.restrictEndpointUsage` organization policy constraint to block\nrequests to the global API endpoint. For more information, see\n[Restricting endpoint usage](/assured-workloads/docs/restrict-endpoint-usage).\n\nWhat's next\n\n- Learn about the Firestore [data model](/firestore/docs/data-model).\n- [Best practices](/firestore/docs/best-practices) for using Firestore."]]