Distributed Systems Explained

A distributed system is a set of programs on different machines that work together as one: a website behind a load balancer, services that talk through a message broker, a database split across servers. These guides explain the parts such systems are built from and the trade-offs between them, one idea at a time, each with a diagram.

Where to start

The core trade-off

  • CAP Theorem

    The CAP theorem in plain terms: consistency, availability and partition tolerance, why a network partition forces a CP vs AP choice, real database examples, PACELC, and FAQs.

Basic Components

The parts most systems are built from: what each one does and when you need it.

  • Load Balancer

    How a load balancer distributes traffic across servers: algorithms (round robin, least connections, hashing), active health checks, Layer 4 vs Layer 7, TLS termination, and FAQs.

  • CDN

    What a Content Delivery Network (CDN) is, how edge caching cuts latency, push vs pull CDNs, Cache-Control headers, origin offload, and how to set one up.

  • Caching

    How caching works in distributed systems: cache-aside, write-through and write-behind patterns, TTL and event-driven invalidation, LRU/LFU eviction, and common failure modes.

  • API Gateway

    What an API Gateway is in distributed systems, how it handles routing, authentication, rate limiting and protocol translation, API Gateway vs Load Balancer, BFF pattern, and FAQs.

  • Rate Limiter

    What a rate limiter is, how Token Bucket, Leaky Bucket, Fixed Window, and Sliding Window algorithms work, distributed rate limiting with Redis, HTTP 429 headers, and FAQs.

  • DNS

    How DNS resolves domain names to IP addresses, recursive vs authoritative servers, DNS record types (A, AAAA, CNAME, NS, TXT), TTL caching, GeoDNS, and failover trade-offs.

  • Message Queue & Broker

    How message queues and brokers decouple microservices: point-to-point queues vs pub/sub event logs, Kafka vs RabbitMQ vs SQS, delivery guarantees, backpressure, and dead-letter queues.

  • Object Storage

    What object storage is (Amazon S3, GCS, Cloudflare R2), how it differs from block and file storage, presigned URL direct uploads, erasure coding durability, multipart uploads, and FAQs.

  • Service Discovery

    What service discovery is in microservices, client-side vs server-side discovery patterns, service registries (Consul, etcd, Eureka, Kubernetes CoreDNS), heartbeats, and FAQs.

Data & Scaling

How data is split, copied and kept consistent across machines.

  • Consistent Hashing

    What consistent hashing is, why modulo hashing (hash % N) causes massive cache misses when nodes change, how the hash ring and virtual nodes work, and real-world uses.

  • Sharding & Replication

    How database replication and sharding scale distributed systems: primary-replica vs multi-primary, hash vs range sharding, hot partitions, cross-shard joins, and FAQs.

  • Database Indexing

    How database indexes speed up queries: B-Trees vs LSM-Trees (MemTable, WAL, SSTables, Bloom filters), composite and covering indexes, inverted indexes, write amplification, and FAQs.

  • Partitioning Strategies

    Deep dive into data partitioning strategies: range vs hash vs composite partitioning, hot-key salting, fixed vs dynamic rebalancing, and local vs global secondary indexes.

  • Consensus & Raft

    What distributed consensus is, how the Raft algorithm solves leader election and log replication using majority quorums, split-brain prevention, Raft vs Paxos, and FAQs.

  • Distributed Transactions

    How distributed transactions work across microservices and sharded databases: Two-Phase Commit (2PC) vs Saga pattern (choreography vs orchestration), transactional outbox, and FAQs.

Coupling

How services come to depend on each other, and how to loosen the ties.

  • Coupling

    Tight vs loose coupling in distributed systems, and the five types of coupling between services (domain, temporal, pass-through, common, content) with examples.

  • Domain Coupling

    What domain coupling is in microservices, why it is the loosest form of inter-service coupling, an order-management example, and how bounded contexts and domain events keep it under control.

  • Temporal Coupling

    What temporal coupling is in microservices, why synchronous call chains hurt availability and latency, an order-creation example, and how queues, events, outbox, and circuit breakers fix it.

  • Pass-through Coupling

    What pass-through coupling is in microservices, why forwarding unused data through an intermediary service causes coupled deployments, an order-inventory-delivery example, and how to fix it.

  • Common Coupling

    Explore common coupling in distributed systems, its challenges, and strategies to mitigate risks. Learn how to improve system architecture and maintain data integrity.

  • Content Coupling

    Explore content coupling in distributed systems, its challenges, and strategies to mitigate risks. Learn how to improve system architecture and maintain service independence.

Messaging

How services exchange messages through a broker, and the kinds of message they send.

  • Messaging

    How asynchronous messaging works between microservices: sender, message broker, receiver, point-to-point queues vs pub/sub topics, delivery guarantees, and how it removes temporal coupling.

  • Message Structure

    Anatomy of a message in distributed messaging systems: header metadata (message ID, correlation ID, group ID, sequence number, expiry) and the three payload types (command, event, document).

  • Command Message

    What a command message is in distributed messaging, write vs query commands, fire-and-forget vs request-reply messaging, orchestration sagas, and command vs event messages.

  • Event Message

    What an event message is in microservices: Event with Detail (Event-Carried State Transfer) vs Event with Identifier (notification event), pros, cons, JSON examples, and choreography sagas.

  • Document Message

    What a document message is in distributed messaging: transferring entity snapshots in Change Data Capture (CDC) pipelines, request-reply responses, and event payloads, with JSON examples.