System Design Concepts

Jul 1, 2024

System Design Concepts Lecture

Introduction

  • Purpose: Understanding essential system design concepts for building scalable applications and passing system design interviews.
  • Topics: Networking, API patterns, databases, etc.

Scaling Servers

Vertical Scaling

  • Adding resources like RAM or upgrading CPU.
  • Simple but limited.

Horizontal Scaling

  • Adding server replicas to handle subsets of requests.
  • Benefits: Increases redundancy and fault tolerance.
  • Requires load balancing to distribute requests effectively.

Load Balancers

  • Acts as a reverse proxy to distribute incoming requests to servers.
  • Algorithms: Round robin, hashing request IDs, location-based routing.

Content Delivery Networks (CDNs)

  • Serve static files (e.g., images, videos, HTML, CSS, JavaScript) from globally distributed servers.
  • Push or pull basis for copying files from origin server.

Caching

  • Creating copies of data for faster refetching.
  • Levels: Disk, memory, CPU cache.

Networking Basics

  • IP addresses: Unique identifiers for devices on a network.
  • TCP/IP Suite: Includes TCP & UDP.
  • TCP: Reliable protocol ensuring packet delivery.
  • Application protocols built on TCP: HTTP, Websockets.

Domain Name System (DNS)

  • Maps domain names to IP addresses using DNS queries.
  • DNS A record for specifying IP addresses.
  • OS caching to reduce repeated DNS queries.

HTTP and API Patterns

HTTP Protocol

  • Follows client-server model.
  • Request: Header (metadata) + Body (content).

REST APIs

  • Stateless and consistent guidelines.
  • Response Codes: 200 (success), 400 (client error), 500 (server error).

GraphQL

  • Single request (query) to fetch multiple resources.
  • Minimizes over-fetching data.

gRPC

  • RPC framework, efficient for server-to-server communication.
  • Uses protocol buffers for data serialization.
  • gRPC Web allows browser usage.

Websockets

  • Bi-directional communication for real-time applications like chat apps.
  • Immediate message delivery without polling.

Databases

Relational Databases (SQL)

  • Examples: MySQL, PostgreSQL.
  • Structured data in rows and tables.
  • ACID compliance: Atomicity, Consistency, Isolation, Durability.

NoSQL Databases

  • Types: Key-value stores, document stores, graph databases.
  • Not ACID compliant, easier to scale.

Database Scaling

Sharding

  • Horizontal scaling by distributing data across machines using shard keys.

Replication

  • Leader-follower: Leader handles writes; followers replicate data for reads.
  • Leader-leader: Every replica can read/write but may result in data inconsistency.

CAP Theorem

  • Trade-offs in a replicated database: Consistency vs. Availability during network partition.
  • PACELC Theorem: More complete version of CAP.

Message Queues

  • Durable storage and redundancy options.
  • Use cases: Handling more data than can be processed immediately, decoupling app components.

Learning Resources

  • System Design for Beginners Course on neetcode.io.
  • System Design Interview Course on neetcode.io.

Conclusion

  • Importance: Preparing for scalable app development and system design interviews.
  • Thanks for support.