System Design 101

repository·main·Indexed 13 days ago

https://github.com/bytebytegohq/system-design-101

An educational resource explaining complex systems, distributed architecture, and software engineering fundamentals using visuals and simple terms. Covers API design, networking protocols, database patterns, security, DevOps, and real-world case studies from companies like Netflix, Uber, and Discord. Includes guides on cloud computing, AI/ML infrastructure, and foundational computer science concepts.

Tokens
130.5K
Snippets
41
Records
870
Agent score
99%

What's inside System Design 101

  1. Overview of Resiliency Patterns

    main

    Resiliency patterns are cloud design patterns used to reduce the damage caused by minor errors that can escalate into system-wide failures (the 'snowball effect'). These patterns are typically used in combination rather than in isolation to build robust distributed systems.

    The 8 core resiliency patterns are:

    • Timeout: Prevents a system from waiting indefinitely for a response.
    • Retry: Attempts to re-execute a failed operation.
    • Circuit breaker: Stops requests to a failing service to allow it to recover.
    • Rate limiting: Controls the rate of incoming requests to prevent exhaustion.
    • Load shedding: Drops excess requests when the system is overloaded.
    • Bulkhead: Isolates failures by partitioning resources.
    • Back pressure: Signals upstream components to slow down production when downstream components are overwhelmed.
    • Let it crash: Allows a process to fail and be restarted by a supervisor to return to a clean state.
  2. Overview of the Top 7 Distributed System Patterns

    main

    This guide identifies the seven most common patterns used in distributed system design to solve challenges related to scalability, reliability, and data consistency. These patterns include:

    • Ambassador: A pattern where a helper service (the ambassador) handles common tasks like logging, monitoring, or security on behalf of a primary service.
    • Circuit Breaker: A pattern used to prevent a system from repeatedly trying to execute an operation that is likely to fail, allowing the system to recover and preventing cascading failures.
    • CQRS (Command Query Responsibility Segregation): A pattern that separates read (query) operations from write (command) operations to optimize performance and scalability.
    • Event Sourcing: A pattern where state changes are captured as a sequence of immutable events rather than just storing the current state.
    • Leader Election: A pattern used to designate a single node as the coordinator or 'leader' among a cluster of nodes to manage shared resources or tasks.
    • Publisher/Subscriber (Pub/Sub): A messaging pattern where senders (publishers) do not program the messages to be sent directly to specific receivers, but instead categorize messages into classes/topics that subscribers listen to.
    • Sharding: A database partitioning pattern that breaks a large dataset into smaller, more manageable pieces (shards) distributed across multiple nodes.
  3. Overview of the top 5 deployment strategies

    main

    This guide identifies the five most common strategies used for software releases to balance speed, risk, and availability:

    1. Big Bang Deployment: The entire system is updated at once. This is high-risk as it requires downtime and makes rollbacks difficult if errors occur.
    2. Rolling Deployment: Updates are applied to instances incrementally (one by one or in small batches). This maintains availability but can lead to version mismatch issues during the transition.
    3. Blue-Green Deployment: Two identical production environments exist (Blue and Green). One is live, while the other receives the new version. Traffic is switched instantly once the new version is verified, allowing for near-instant rollbacks.
    4. Canary Deployment: The new version is rolled out to a small subset of users first. If no issues are detected, it is gradually expanded to the rest of the infrastructure.
    5. Feature Toggle: Code is deployed to production but remains inactive behind a conditional flag. Features are enabled for specific users or segments without requiring a new deployment.
  4. Overview of popular API protocols

    main

    This guide provides a high-level overview of the six most common API protocols used in modern web development. Understanding these protocols helps in choosing the right communication pattern for specific system design requirements:

    • REST (Representational State Transfer): A common architectural style for web services.
    • Webhooks: A way for one system to provide real-time information to another via HTTP callbacks.
    • GraphQL: A query language for APIs that allows clients to request exactly the data they need.
    • SOAP (Simple Object Access Protocol): A protocol for exchanging structured information in web services.
    • WebSocket: A protocol providing full-duplex communication channels over a single TCP connection.
    • gRPC (Google Remote Procedure Call): A high-performance, open-source RPC framework.
  5. Overview of iQIYI's Database Stack

    main

    iQIYI, a large-scale online video platform, utilizes a diverse set of relational and NoSQL databases to handle its massive scale. Their stack includes:

    • Relational/Hybrid: MySQL, TiDB (a hybrid transactional/analytical processing (HTAP) distributed database), and TokuDB (an open-source storage engine for MySQL and MariaDB).
    • NoSQL/Document: Redis, Couchbase (distributed multi-model NoSQL document-oriented database), MongoDB, and TiKV.
    • Big Data/Analytical: Hive and Impala.
    • Other: HiGraph.
  6. Overview of Reddit's Core Architecture

    main

    Reddit's architecture is designed to serve over 1 billion monthly users by transitioning from a Python-based monolith to a microservices architecture built with Go. The system utilizes a multi-layered approach for request routing, data storage, and asynchronous processing.

    Key Architectural Components:

    • Edge & Routing: Uses a Fastly CDN as the front end, followed by a load balancer that routes requests to appropriate services.
    • API Layer: Primarily uses GraphQL. The architecture has evolved from a GraphQL monolith to GraphQL Federation, which combines multiple Domain Graph Services (DGS). Core entities are served via Go subgraphs.
    • Data Storage:
      • Postgres: Serves as the primary core data model.
      • Memcached: Used in front of Postgres to reduce database load.
      • Cassandra: Utilized for new features due to its high resiliency and availability.
      • Debezium: Implements Change Data Capture (CDC) to support data replication and maintain cache consistency.
    • Asynchronous Processing & Messaging:
      • RabbitMQ: An async job queue used to defer expensive operations (e.g., user voting, submitting links) to job workers.
      • Kafka: Used for real-time data transfer to perform content safety checks and moderation rules.
    • Infrastructure & Deployment:
      • Hosting: AWS and Kubernetes.
      • CI/CD & IaC: Spinnaker, Drone CI, and Terraform.
  7. Understand the core features and architecture of Elasticsearch

    main

    Elasticsearch is a distributed, multitenant-capable full-text search engine built on top of the Lucene library. It provides an HTTP web interface and supports schema-free JSON documents.

    Key features include:

    • Real-time full-text search: Rapidly query text-based data.
    • Analytics engine: Perform complex data analysis.
    • Distributed Lucene: Leverages Lucene's capabilities across a distributed cluster.

    To master Elasticsearch, focus on its core data structures, specifically how it builds the term dictionary using an LSM Tree (Log-Structured Merge Tree) for indexing.

  8. Analyze the Netflix database tech stack by use case

    main

    Netflix utilizes a polyglot persistence strategy, selecting specific database types based on the requirements of different services. Use the following mapping to understand which database categories are appropriate for specific workloads:

    • Relational (ACID compliance): Use MySQL for billing, subscriptions, taxes, and revenue. Use CockroachDB for multi-region active-active architectures, global transactions, and data pipeline workflows.
    • Columnar (Analytics): Use Redshift and Druid for structured data storage and processing with Spark. Use Tableau for visualization.
    • Key-Value (Caching): Use EVCache (built on Memcached) for high-scale caching of service data like homepages and personal recommendations.
    • Wide-Column (High Availability/Scale): Use Cassandra for high-volume data such as Video/Actor info, User Data, Device info, and Viewing History.
    • Time-Series (Metrics): Use Atlas (an in-memory database) for metrics storage and aggregation.
    • Unstructured (Object Storage): Use S3 for images, videos, metrics, and log files. Use Apache Iceberg alongside S3 for big data storage management.
  9. Key characteristics of the DeepSeek-R1 model

    main

    DeepSeek-R1 is a reasoning-focused AI model released in January 2025. It is designed for high efficiency in mathematics, coding, and reasoning tasks. Key technical specifications include:

    • Architecture: Mixture-of-Experts (MoE) with 671 billion total parameters, activating only 37 billion parameters per task.
    • Training Data: Pre-trained on 14.8 trillion tokens across 52 languages.
    • Training Efficiency: Trained using 2,000 Nvidia GPUs (significantly fewer than competitors like GPT-4).
    • Cost-Effectiveness: Approximately 85-90% more cost-effective than competitors.
    • License: Released as open-source under the MIT license.
  10. Compare the 6 primary database models

    main

    When designing a system, choose a database model based on your data structure and access patterns. The six primary models are:

    1. Flat Model: Data is organized into a single table (rows and columns) similar to a spreadsheet. Best for simple data with no complex relationships.
    2. Hierarchical Model: Data is organized in a tree structure where each record has one parent and multiple children. Best for clear parent-child relationships, but poor for many-to-many relationships.
    3. Relational Model: Data is represented in tables (relations) using rows (tuples) and columns (attributes). It uses keys and normalization to ensure integrity and is the standard for SQL-based systems. It excels at handling many-to-many relationships and complex queries.
    4. Star Schema: A specialized model for OLAP (Online Analytical Processing) in data warehousing. It consists of a central fact table (quantitative data) surrounded by dimension tables (descriptive attributes). Optimized for fast analytical query performance by minimizing joins.
    5. Snowflake Model: A normalized version of the Star Schema where dimension tables are split into multiple related tables. This improves storage efficiency and data integrity but increases query complexity due to more joins.
    6. Network Model: A graph-based structure where records can have multiple parents and multiple children. This is used to represent complex relationships and many-to-many connections more efficiently than the hierarchical model.
  11. Identify common C++ use cases

    main

    C++ is a versatile language used in performance-critical and resource-constrained environments. Key industries and applications include:

    • Embedded Systems: Leveraging efficiency and fine hardware control.
    • Game Development: Utilizing high performance and efficiency.
    • Operating Systems: Providing extensive control over system resources and memory for OS and low-level utilities.
    • Databases: Implementing high-performance systems for efficient memory management and fast query execution.
    • Financial Applications: Used in high-frequency trading and other performance-sensitive financial software.
    • Web Browsers: Developing browsers and core components like rendering engines.
    • Networking: Developing network devices and simulation tools.
    • Scientific Computing: Powering engineering and scientific applications requiring high performance and precise computational control.