The Scatter Gather Tax
Figma shards Postgres behind DBProxy, a query engine that parses SQL, extracts the logical shard ids, and rewrites the query for the physical database. Shard keys are hashed, so rows with adjacent ids do not sit together.
A nightly job runs this against a table sharded by FileID, spread over 64 physical shards:
SELECT id, file_id, updated_at
FROM file_revisions
WHERE updated_at > now() - interval '1 hour'
ORDER BY updated_at
LIMIT 500;
A reviewer says the job is now 64 times cheaper because each shard only scans a 64th of the table. What actually happens?
Sign in to answer questions and track your progress
Sign In