Skip to content

Instantly share code, notes, and snippets.

@vasanthk
Last active February 23, 2024 14:25
Star You must be signed in to star a gist
Save vasanthk/485d1c25737e8e72759f to your computer and use it in GitHub Desktop.
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
  • Constraints
    • Mainly identify traffic and data handling constraints at scale.
    • Scale of the system such as requests per second, requests types, data written per second, data read per second)
    • Special system requirements such as multi-threading, read or write oriented.
  1. High level architecture design (Abstract design)
  • Sketch the important components and connections between them, but don't go into some details.
    • Application service layer (serves the requests)
    • List different services required.
    • Data Storage layer
    • eg. Usually a scalable system includes webserver (load balancer), service (service partition), database (master/slave database cluster) and caching systems.
  1. Component Design
  • Component + specific APIs required for each of them.
  • Object oriented design for functionalities.
    • Map features to modules: One scenario for one module.
    • Consider the relationships among modules:
      • Certain functions must have unique instance (Singletons)
      • Core object can be made up of many other objects (composition).
      • One object is another object (inheritance)
  • Database schema design.
  1. Understanding Bottlenecks
  • Perhaps your system needs a load balancer and many machines behind it to handle the user requests. * Or maybe the data is so huge that you need to distribute your database on multiple machines. What are some of the downsides that occur from doing that?
  • Is the database too slow and does it need some in-memory caching?
  1. Scaling your abstract design
  • Vertical scaling
    • You scale by adding more power (CPU, RAM) to your existing machine.
  • Horizontal scaling
    • You scale by adding more machines into your pool of resources.
  • Caching
    • Load balancing helps you scale horizontally across an ever-increasing number of servers, but caching will enable you to make vastly better use of the resources you already have, as well as making otherwise unattainable product requirements feasible.
    • Application caching requires explicit integration in the application code itself. Usually it will check if a value is in the cache; if not, retrieve the value from the database.
    • Database caching tends to be "free". When you flip your database on, you're going to get some level of default configuration which will provide some degree of caching and performance. Those initial settings will be optimized for a generic usecase, and by tweaking them to your system's access patterns you can generally squeeze a great deal of performance improvement.
    • In-memory caches are most potent in terms of raw performance. This is because they store their entire set of data in memory and accesses to RAM are orders of magnitude faster than those to disk. eg. Memcached or Redis.
    • eg. Precalculating results (e.g. the number of visits from each referring domain for the previous day),
    • eg. Pre-generating expensive indexes (e.g. suggested stories based on a user's click history)
    • eg. Storing copies of frequently accessed data in a faster backend (e.g. Memcache instead of PostgreSQL.
  • Load balancing
    • Public servers of a scalable web service are hidden behind a load balancer. This load balancer evenly distributes load (requests from your users) onto your group/cluster of application servers.
    • Types: Smart client (hard to get it perfect), Hardware load balancers ($$$ but reliable), Software load balancers (hybrid - works for most systems)

Load Balancing

  • Database replication
    • Database replication is the frequent electronic copying data from a database in one computer or server to a database in another so that all users share the same level of information. The result is a distributed database in which users can access data relevant to their tasks without interfering with the work of others. The implementation of database replication for the purpose of eliminating data ambiguity or inconsistency among users is known as normalization.
  • Database partitioning
    • Partitioning of relational data usually refers to decomposing your tables either row-wise (horizontally) or column-wise (vertically).
  • Map-Reduce
    • For sufficiently small systems you can often get away with adhoc queries on a SQL database, but that approach may not scale up trivially once the quantity of data stored or write-load requires sharding your database, and will usually require dedicated slaves for the purpose of performing these queries (at which point, maybe you'd rather use a system designed for analyzing large quantities of data, rather than fighting your database).
    • Adding a map-reduce layer makes it possible to perform data and/or processing intensive operations in a reasonable amount of time. You might use it for calculating suggested users in a social graph, or for generating analytics reports. eg. Hadoop, and maybe Hive or HBase.
  • Platform Layer (Services)
    • Separating the platform and web application allow you to scale the pieces independently. If you add a new API, you can add platform servers without adding unnecessary capacity for your web application tier.
    • Adding a platform layer can be a way to reuse your infrastructure for multiple products or interfaces (a web application, an API, an iPhone app, etc) without writing too much redundant boilerplate code for dealing with caches, databases, etc.

Platform Layer

Key topics for designing a system

  1. Concurrency
  • Do you understand threads, deadlock, and starvation? Do you know how to parallelize algorithms? Do you understand consistency and coherence?
  1. Networking
  • Do you roughly understand IPC and TCP/IP? Do you know the difference between throughput and latency, and when each is the relevant factor?
  1. Abstraction
  • You should understand the systems you’re building upon. Do you know roughly how an OS, file system, and database work? Do you know about the various levels of caching in a modern OS?
  1. Real-World Performance
  • You should be familiar with the speed of everything your computer can do, including the relative performance of RAM, disk, SSD and your network.
  1. Estimation
  • Estimation, especially in the form of a back-of-the-envelope calculation, is important because it helps you narrow down the list of possible solutions to only the ones that are feasible. Then you have only a few prototypes or micro-benchmarks to write.
  1. Availability & Reliability
  • Are you thinking about how things can fail, especially in a distributed environment? Do know how to design a system to cope with network failures? Do you understand durability?

Web App System design considerations:

  • Security (CORS)
  • Using CDN
    • A content delivery network (CDN) is a system of distributed servers (network) that deliver webpages and other Web content to a user based on the geographic locations of the user, the origin of the webpage and a content delivery server.
    • This service is effective in speeding the delivery of content of websites with high traffic and websites that have global reach. The closer the CDN server is to the user geographically, the faster the content will be delivered to the user.
    • CDNs also provide protection from large surges in traffic.
  • Full Text Search
    • Using Sphinx/Lucene/Solr - which achieve fast search responses because, instead of searching the text directly, it searches an index instead.
  • Offline support/Progressive enhancement
    • Service Workers
  • Web Workers
  • Server Side rendering
  • Asynchronous loading of assets (Lazy load items)
  • Minimizing network requests (Http2 + bundling/sprites etc)
  • Developer productivity/Tooling
  • Accessibility
  • Internationalization
  • Responsive design
  • Browser compatibility

Working Components of Front-end Architecture

  • Code
    • HTML5/WAI-ARIA
    • CSS/Sass Code standards and organization
    • Object-Oriented approach (how do objects break down and get put together)
    • JS frameworks/organization/performance optimization techniques
    • Asset Delivery - Front-end Ops
  • Documentation
    • Onboarding Docs
    • Styleguide/Pattern Library
    • Architecture Diagrams (code flow, tool chain)
  • Testing
    • Performance Testing
    • Visual Regression
    • Unit Testing
    • End-to-End Testing
  • Process
    • Git Workflow
    • Dependency Management (npm, Bundler, Bower)
    • Build Systems (Grunt/Gulp)
    • Deploy Process
    • Continuous Integration (Travis CI, Jenkins)

Links

System Design Interviewing

Scalability for Dummies

Introduction to Architecting Systems for Scale

Scalable System Design Patterns

Scalable Web Architecture and Distributed Systems

What is the best way to design a web site to be highly scalable?

How web works?

@99ashish
Copy link

99ashish commented Feb 5, 2021

Thanks you so much. It gives enough info for beginner like which basics they need to know before deep dive in the system design.

@Abouba-Haidara
Copy link

Thank You for sharing!

@deekshakaul
Copy link

Great list! Thank you so much for sharing! Came across a great source of system design blogs a while back. It is the only place I have found any discussion for Google Maps system design.

Another thing you might want to add is how to pick the right database based on the requirements and limitations. Here is a youtube video for the same.

@Brijwizards
Copy link

Great list of resources. Thanks for sharing it.

@petrind
Copy link

petrind commented Jul 23, 2021

Thanks for sharing these notes.
It is really understandable.

@yuliiakorabelska
Copy link

Thanks for sharing! Awesome work here!

@asif-simform
Copy link

Awesome! Man :)

@bilalislam
Copy link

thanks a lot :)

@Codes-Lab
Copy link

Super

@codaroma
Copy link

I've heard of "use cases" and I've heard of "user stories", but "user cases" is a new one for me. Is this a crossover?

@0bit093
Copy link

0bit093 commented Aug 5, 2022

nice info.

@mahdiazizzadeh
Copy link

wow, it's awesome. thanks a lot

@pwalters04
Copy link

@vasanthk, for How to rock a systems design interview, this is a 404 currently

@Guadalupe112
Copy link

Excellent article. A minor correction. 1 day equals 86400 seconds. (~100,000). approximately 105 seconds Please update this and any future capacity estimates to reflect this change. uno online

@truonghatsts
Copy link

Great resources!

@HerrineKim
Copy link

Thank you!

@ju-c
Copy link

ju-c commented Jul 5, 2023

Great work. Thanks for sharing!

@Almazatun
Copy link

Thank you 👍!

@dilshanrlk
Copy link

Supper info

@zymbaluk
Copy link

Amazingly helpful thank you so much

@rahul3355
Copy link

Great resource!

@Filliners
Copy link

Envisioning a comprehensive system design cheatsheet seemed like a daunting task, and I found myself grappling with the complexities of organizing vast amounts of information. That's when I turned to a reputable software development company https://www.intellectsoft.net/blog/top-software-development-companies-in-miami/ for assistance. Their expertise in crafting intuitive and effective solutions became the cornerstone of my journey. From the initial consultation to the final delivery, the team demonstrated a profound understanding of system design principles. They meticulously analyzed my requirements, helping me distill intricate concepts into digestible components. The collaboration was marked by a seamless exchange of ideas, transforming my vision into a tangible and user-friendly cheatsheet. The company's commitment to quality shone through in the intuitive user interface, thoughtful information architecture, and attention to detail. The cheatsheet not only became a valuable reference tool but also a testament to the power of professional collaboration in software development. In essence, this software development company not only alleviated the challenges I faced but also elevated the entire process. The cheatsheet now stands as a testament to their commitment to excellence and has become an indispensable asset in my pursuit of mastering system design concepts.

@ethanappgenius
Copy link

Absolutely, the key topics you've outlined for designing a system are fundamental pillars in the world of software development. When it comes to concurrency, understanding threads, deadlock, and starvation is crucial for creating robust systems. Moreover, the ability to parallelize algorithms can significantly impact performance. Networking knowledge is equally vital, and a grasp of IPC and TCP/IP, along with distinguishing between throughput and latency, is indispensable. Abstraction is the bridge between high-level development and the underlying systems; comprehending how an OS, file system, and database work provides the foundation for effective software architecture. Real-world performance considerations, including the understanding of hardware speeds and the relative performance of RAM, disk, SSD, and networks, ensure that developers are equipped to optimize their applications efficiently.

In the context of game development and augmented reality app creation, these principles remain pertinent. Unreal Engine game development demands a robust understanding of concurrency, especially when optimizing game loops and handling multithreading for enhanced performance. Networking skills are crucial for online multiplayer functionalities, and considerations of real-world performance become paramount when creating resource-intensive game environments. Abstraction in this domain involves not only understanding the Unreal Engine framework but also the underlying hardware to create seamless gaming experiences. Additionally, the principles of availability and reliability are essential in both Unreal Engine game development and augmented reality app development, where system failures or network disruptions can significantly impact user experiences. So, as we delve into the intricacies of system design, let's not forget to apply these principles to our endeavors in the exciting realms of Unreal Engine and augmented reality app development.

@adnan-koder
Copy link

Wow, what an extensive guide to system architecture and development! This breakdown of essential steps is invaluable for app design and development. As someone deeply involved in the mobile app development industry and seeking insights from top mobile app development companies, this guide stands out. Your emphasis on load balancing, database replication, and platform layers resonates deeply with our work at a leading mobile app development company in Dallas. Understanding these intricacies is vital in delivering top-tier solutions. Your comprehensive breakdown truly makes navigating system architecture a breeze!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment