Core Building Blocks
The parts every design uses: databases, caches, queues, CDNs and more.
- 1 Database "Orders need transactions and have clear relationships, so I'll use Postgres. Primary key is order_id, and the main query, a user's recent orders, is served by an index on user_id and created_at. Reads are about 50 to 1, so I'll add read replicas and a cache, and read a user's own new order from ...
- 2 Cache "Product reads are about 50 to 1 over writes and most traffic hits a few thousand popular items, so I'll put Redis in front of the product table with cache-aside. Key is product:{id}, value is the serialized product, TTL ten minutes with some jitter. On update we write the database and delete the...
- 3 CDN "Images and video segments are read by many users and never change, so they go to blob storage behind a CDN. File names include a content hash, so they can be cached for a year and we never purge on deploy. Private videos use signed URLs that expire after a few hours. With a 95% hit rate the orig...
- 4 Message Queue "The order is saved synchronously, and everything else, email, inventory sync, analytics, goes through an order-placed topic so checkout replies in about 30 ms. Delivery is at-least-once, so every consumer is idempotent on order_id. Events are partitioned by order_id to keep each order's events i...
- 5 Blob Storage "Video bytes go to blob storage and the metadata, owner, key, size and status, goes to Postgres. The client gets a presigned multipart upload URL and sends the file straight to the bucket, so our servers never carry it. When the upload completes, an event marks it ready and kicks off transcoding....
- 6 API Gateway "Clients hit the API gateway first. It terminates TLS, verifies the JWT locally using cached keys, and applies a per-user token-bucket rate limit backed by Redis, returning 429 when exceeded. Then it routes by path to each service's load balancer and adds the verified user ID and a request ID. It...
- 7 Elasticsearch "Search needs ranking and typo tolerance, so I'll index products in Elasticsearch. Postgres stays the source of truth, and changes stream in through CDC to an indexer, so search is about a second behind. Title and description are analyzed text; brand and category are keywords for filters and face...