r/FastAPI • • Apr 02 '25

Hosting and deployment GCP Latency

I try to query GCP Big query table by using python big query client from my fastAPI. Filter is based on tuple values of two columns and date condition. Though I'm expecting few records, It goes on to scan all the table containing millions of records. Because of this, there is significant latency of >20 seconds even for retrieving single record. Could someone provide best practices to reduce this latency. FastAPI server is running on container in a private cloud (US).

1 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/International-Rub627 Apr 04 '25

Updated the query (Reddit Query) for your info.

2

u/TeoMorlack Apr 04 '25

I saw your update and just wanted to add, this is not an issue with fastapi or the bigquery connection/query. It’s a problem that you have to deal with on the source table. Usually with a relational database you would index filter columns to provide fast lookups. On bigquery you can work with clustering and partitioning instead to avoid scanning the whole table and reducing the size of record read. Can you identify a field on which the table is partitioned to use in the query? Or do you have control on said table to add this kind of optimisation? If you need some guidance I can provide some help :)