A while ago, I realized I wanted to code big, fun applications, but I lacked the skills. One skill I was missing was system design. So, for the past week or so, I’ve been reading up on System Design Primer, a resource that everyone online seems to recommend.
Here are my three favourite takeaways:
Takeaway #1: The Peril of Local Session Storage#
Storing user session data on a server’s local disk is a bad idea.
Example: If a user logs into one server, and on a subsequent request, they are routed to another server where their session data isn’t stored, they’ll be unexpectedly logged out. This can create a frustrating user experience.
Solution: Use a shared session store, like a distributed cache or a dedicated session database, to ensure consistency across all servers.
Takeaway #2: Caching is Everywhere, And It’s Awesome#
CDNs are caches. Static sites are caches. Caches can save you from repeating the same expensive database queries over and over. They are easy to implement and can provide immense performance boosts.
Example: By caching the results of a database query in memory, subsequent requests can be served from the cache, dramatically reducing load on the database and speeding up response times.
Takeaway #3: CAP Theorem#
The CAP theorem states that in a distributed system, you can only have two out of three guarantees: Consistency, Availability, and Partition Tolerance.
Explanation: Consistency ensures that all nodes see the same data simultaneously. Availability ensures that every request receives a response, even if it’s not the most recent data. Partition Tolerance means the system continues to operate despite network partitions.
Practical Impact: You must choose which two of the three properties are most important for your system, as you can’t optimize for all three simultaneously.
Sources#
- Harvard CS74 Lecture on Scalability
- Le Cloud Blog’s Scalability Articles
- System Design Primer GitHub Repo
- ChatGPT 4o and Claude 3.5 Sonnet