Fundamentals

Basic Principles

Trade-offs

The Trade-off Between Consistency and Availability

The article explains the CAP theorem (Consistency, Availability, Partition tolerance) and the trade-off between consistency (data is always in sync on every node) and availability (the system always responds to requests). In a distributed system you cannot guarantee all three at once; you usually have to choose between C and A when a network partition (P) occurs. This trade-off sets the baseline for the rest of the note. The sections after it collect eight common problems with the solutions usually applied to them, such as caching, async writes, redundancy, load balancing, CDN, object storage, centralized logging, and sharding with indexes. A closing list points to further reading. Source: https://viblo.asia/p/danh-doi-giua-tinh-nhat-quan-va-tinh-san-sang-tradeoff-between-consistency-and-availability-5OXLAvlxVGr

Common Problems and Solutions in System Design

Below are 8 common system design problems and the solutions usually applied to them:

  1. Caching – speed up reads

    • Problem: a large volume of read queries overloads the database (DB).
    • Solution: use caching systems such as Redis or Memcached to store the results of popular queries, reducing DB load and speeding up responses.
  2. Async Write & LSM-Tree DB – handle writes efficiently

    • Problem: a high write volume bottlenecks the DB and hurts performance.
    • Solution: use asynchronous writes through a message queue such as Kafka or RabbitMQ. Use DBs optimized for writes, such as Cassandra and RocksDB (which use the Log-Structured Merge-Tree, LSM-Tree, structure).
  3. Redundancy & Failover – increase availability

    • Problem: the system has a Single Point of Failure (SPOF) when there is only one server or one critical component.
    • Solution: deploy data replication and automatic failover between the primary server (master) and replica servers so the system keeps working when something fails.
  4. Load Balancer – distribute load

    • Problem: servers get overloaded when traffic increases.
    • Solution: use a Load Balancer such as Nginx or AWS Application Load Balancer (ALB) to distribute user requests evenly across multiple servers, so no single server is overloaded.
  5. CDN (Content Delivery Network) – reduce latency

    • Problem: users geographically far from the main server experience high latency when accessing content.
    • Solution: use a Content Delivery Network (CDN) such as Cloudflare or AWS CloudFront to store copies of static files (images, video, CSS, JavaScript) on edge servers close to users, reducing latency and speeding up page loads.
  6. Block/Object Storage – manage large files

    • Problem: storing large files directly in the DB bloats the DB, slows queries, and makes management difficult.
    • Solution: use block storage such as Amazon EBS or object storage such as Amazon S3 for large files. The files' metadata (e.g. path, file name, size) can be stored in the DB.
  7. Centralized Logging – manage logs effectively

    • Problem: it is hard to search and analyze error logs when the system spans many servers.
    • Solution: use a centralized log management system such as the ELK stack (Elasticsearch, Logstash, Kibana) or the EFK stack (Elasticsearch, Fluentd, Kibana) to collect, store, search, and analyze logs from all system components in one place.
  8. Sharding & Index – optimize queries

    • Problem: slow queries on large DBs.
    • Solution:
      • Create indexes on fields frequently used in query conditions to speed up lookups.
      • Apply sharding (data partitioning) to split a large DB into smaller parts (shards), each stored on a separate node, which spreads load and improves query performance.

References and Tools

See also: Overview · Technical Solutions · Software Architecture · GonnaCrash · Breakscale · Sys0 · Syscraft