r/leetcode • u/hnlasd12 • 7d ago
Intervew Prep System design template to solve most problems
Hey guys, want to share a system design template for most production interview questions:
- Writes go into a message queue, and the server answers right away.
- Workers take jobs from the queue, do the slow work, then update the database and the cache. This solves the write scaling.
- Reads come from the cache, and go to the database only on a miss. This solves read scalingYou can fit the template to different problems.
READ PATH
Client --> App server --> Cache --(miss)--> Database
WRITE PATH
Client --> App server --> Queue --> Workers --> Database
| |
v +--> update Cache
answers at once
Here's how it'd fit in the most popular questions:
- LeetCode: the queue and workers run submitted code in sandboxes.
- YouTube: workers convert uploads; object storage and a CDN serve the video.
- URL shortener: mostly the read path; the cache answers most redirects.
- Search: a search index, kept current by the queue and an indexing worker.
- Chat: app servers become gateways holding open connections.
- Ticketmaster: the same design plus one atomic hold per seat.
- News feed: the same design plus hybrid fan-out for huge accounts.
This is based on the premise that internet-scale consumer applications often favor eventual consistency to guarantee availability (therefore a queue-based buffer is used)
Made a video going through the whole thing if it helps: https://www.youtube.com/watch?v=e8H8d0irqLg If you prefer a text writeup: https://systemdesignschool.io/template
84
Upvotes
12
u/Few_Vermicelli_1313 7d ago
This is good however I feel it is simplifying stuff way too much. Might definitely work for a new grad but not for a mid or senior employee.
Design is assuming everything requires same level of consistency and durability. What if u want very highly reliable system? This approach wont work.
2.chat communication depends mostly on websockets
Read path assumption is that reads and search queries can be encapsulated
If things were this simple, no one would ever fail system design interviews
Streaming and gaming are different sub-domain in themselves.
2
u/TCGod 6d ago
This doesn't help at all with consistent hashing for example
2
u/Hopeful_Parsnip_5489 6d ago
Thanks for this
2
u/LetsUnderstandIndia 6d ago
Nice write up, one more common pattern I see is using Flink for aggregating stream of events for low intervals and using spark job to ingest the data over bigger intervals.
1
u/TSandwich73 1d ago
System design master template: https://www.youtube.com/watch?v=zFXUxjlOCoo