AI Hints
Home›System Design Tutorial›Choosing Storage
System Design · Lesson 53 of 120

Practice: Shoply's Data

Which store for what.

⏱ 2 min read▶ Video at 1:02:33🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

Shoply is now big. It has users, orders, product photos, a search box, sessions, and a dashboard of sales per minute. Pause, and decide where each one should live.

Practice: Shoply's Data
From the video: Practice: Shoply's Data
  • Users and orders
  • Photos, search, sessions
  • Sales per minute

One possible answer

Here's one answer. Users, products, and orders go into Postgres, because they're related and need transactions. Product photos go into object storage, behind a CDN. Search uses Elasticsearch, fed from Postgres. Sessions and carts use Redis. And the sales dashboard reads from a time series database.

DataStoreWhy
Users, ordersPostgresrelations, transactions
PhotosS3 + CDNbig files
SearchElasticsearchfull text
Sessions, cartsRedisfast key lookups
Sales per minuteTime-series DBmetrics

Keeping them in sync

With several stores, keep them in sync carefully. Postgres is the source of truth. Changes flow out to the search index, often through a message queue, which we'll meet soon. Redis data can be lost and rebuilt. And photos are referenced by keys stored in Postgres.

keyvalue
Source of truthPostgres
Searchfed by change events
Rediscan be rebuilt
Photoskeys in Postgres

Summary

Real systems use several stores, each for what it does best, with one clear source of truth. Next, a quiz on databases.

Key takeaways
  • Right store for each job
  • One source of truth
  • Sync with events
Next up: Databases Quiz — test yourself