System Design Interview Key Concepts

Aug 6, 2024

System Design Tutorial Summary

Introduction

  • Coverage of core concepts for system design interviews: scalability, reliability, data handling, and high-level architecture.
  • Focus on how to "glue" a system together rather than coding.

High-Level Architecture

  1. Layered System in Computers
    • Functions through binary (0s and 1s).
    • Data Units:
      • Bit: smallest unit (0 or 1)
      • Byte: 8 bits; represents a single character.
      • Larger units: Kilobyte, Megabyte, Gigabyte, Terabyte.
    • Disk Storage:
      • Types: HDD (slower, cheaper) vs. SSD (faster, more expensive).
    • RAM (Random Access Memory):
      • Primary active data holder (volatile memory).
      • Speed: 5,000 MB/sec and above.
    • Cache:
      • Smaller than RAM (measured in MB), faster access times.
      • Levels: L1, L2, L3 caches.
    • CPU (Central Processing Unit):
      • Processes instructions; high-level code compiled into machine code.
    • Motherboard:
      • Connects all components and facilitates data flow.

Production-Ready Architecture

  1. CI/CD Pipeline:
    • Automates deployment processes (e.g., Jenkins, GitHub Actions).
  2. Load Balancers & Reverse Proxies:
    • Distribute user requests across multiple servers.
  3. External Storage:
    • Stores data not on the same server, accessed over the network.
  4. Logging & Monitoring:
    • Tools: PM2 for backend; Sentry for frontend.
    • Alerting services integrated with platforms like Slack.
  5. Debugging Process:
    • Identify issues through logs, replicate in staging, apply hotfixes.

Pillars of System Design

  1. Key Principles:
    • Scalability: system growth with user base.
    • Maintainability: ease of understanding for future developers.
    • Efficiency: optimal use of resources.
  2. Core Elements:
    • Moving Data: seamless data flow.
    • Storing Data: considerations for SQL vs. NoSQL.
    • Transforming Data: turning raw data into meaningful information.

CAP Theorem

  • Components:
    • Consistency: all nodes have the same data.
    • Availability: system is always operational.
    • Partition Tolerance: system functions during network partitions.
  • Only two out of three can be guaranteed in distributed systems.

Availability and Performance

  1. Availability Metrics:
    • Measured in percentages (e.g., 99.9% allows for 8.76 hours of downtime per year).
  2. SLAs & SLOs:
    • SLAs: formal contracts with customers.
    • SLOs: internal performance goals.
  3. Resilience Measures:
    • Redundant systems, graceful degradation, reliability, and fault tolerance.
  4. Performance Metrics:
    • Throughput: amount of data handled over time (RPS, QPS, BPS).
    • Latency: time to handle a single request.

Networking Basics

  1. IP Addresses:
    • IPv4 vs. IPv6 for unique device identification.
  2. Data Communication:
    • Governed by Internet Protocol, includes TCP (reliable) and UDP (faster, less reliable).
  3. DNS (Domain Name System):
    • Translates domain names to IP addresses.
  4. Proxy Servers:
    • Forward and reverse proxies serve different purposes like caching and load balancing.

Application Layer Protocols

  1. HTTP:
    • Request-response protocol, stateless.
    • HTTP methods: GET, POST, PUT, PATCH, DELETE.
  2. WebSockets:
    • Allows real-time, two-way communication.
  3. Email Protocols:
    • SMTP for sending, IMAP/POP3 for retrieving emails.
  4. File Transfer Protocols:
    • FTP for transferring files, SSH for secure remote operations.
  5. RPC (Remote Procedure Call):
    • Invokes code execution on remote servers.

API Design Best Practices

  1. CRUD Operations:
    • Define inputs and outputs for Create, Read, Update, and Delete actions.
  2. Communication Protocols:
    • REST, GraphQL, gRPC for data transport.
  3. Versioning:
    • Maintaining backward compatibility when modifying endpoints.
  4. Rate Limiting & CORS:
    • Prevents abuse and defines access to APIs.

Caching and CDNs

  1. Caching Techniques:
    • Browser, server-side, database caching to improve speed and efficiency.
  2. CDNs (Content Delivery Networks):
    • Distribute static content closer to users to reduce latency.

Load Balancing

  1. Purpose:
    • Distributes traffic to prevent server overload.
  2. Algorithms:
    • Round Robin, Least Connections, IP Hashing, Weighted Algorithms.
  3. Health Checks:
    • Ensures traffic only directed to responsive servers.
  4. Redundancy:
    • Implementing multiple load balancers to avoid single points of failure.

Database Essentials

  1. Types of Databases:
    • Relational Databases (SQL): ACID compliant; examples include Postgres, MySQL.
    • NoSQL Databases: Flexible schema; examples include MongoDB, Redis.
    • In-Memory Databases: Fast access for caching; e.g., Redis.
  2. Scaling Databases:
    • Vertical Scaling: Enhancing a single server.
    • Horizontal Scaling: Distributing data across multiple servers (sharding, replication).
  3. Performance Techniques:
    • Caching, indexing, query optimization.

Conclusion

  • Importance of designing robust systems with a focus on scalability, reliability, and efficient data handling.
  • Understanding trade-offs based on specific use cases is crucial for successful system design.