When designing distributed systems for scalability, reliability, and consistency. Covers CAP/PACELC theorems, consistency models (strong, eventual, causal), replication patterns (leader-follower, multi-leader, leaderless), partitioning strategies (hash, range, geographic), transaction patterns (saga, event sourcing, CQRS), resilience patterns (circuit breaker, bulkhead), service discovery, and caching strategies for building fault-tolerant distributed architectures.
npx skills add https://github.com/ancoleman/ai-design-components --skill designing-distributed-systems
Design scalable, reliable, and fault-tolerant distributed systems using proven patterns and consistency models.
Distributed systems are the foundation of modern cloud-native applications. Understanding fundamental trade-offs (CAP theorem, PACELC), consistency models, replication patterns, and resilience strategies is essential for building systems that scale globally while maintaining correctness and availability.
Apply when:
CAP Theorem: In a distributed system experiencing a network partition, choose between Consistency (C) or Availability (A). Partition tolerance (P) is mandatory.
Network partitions WILL occur → Always design for P
During partition:
├─ CP (Consistency + Partition Tolerance)
│ Use when: Financial transactions, inventory, seat booking
│ Trade-off: System unavailable during partition
│ Examples: HBase, MongoDB (default), etcd
│
└─ AP (Availability + Partition Tolerance)
Use when: Social media, caching, analytics, shopping carts
Trade-off: Stale reads possible, conflicts need resolution
Examples: Cassandra, DynamoDB, Riak
PACELC: Extends CAP to consider normal operations (no partition).
Strong Consistency ◄─────────────────────► Eventual Consistency
│ │ │
Linearizable Causal Consistency Convergent
(Slowest, (Middle Ground, (Fastest,
Most Consistent) Causally Ordered) Eventually Consistent)
Strong Consistency (Linearizability):
Eventual Consistency:
Causal Consistency:
Bounded Staleness:
1. Leader-Follower (Single-Leader):
2. Multi-Leader:
3. Leaderless (Dynamo-style):
Hash Partitioning (Consistent Hashing):
Range Partitioning:
Geographic Partitioning:
Circuit Breaker:
[Closed] → Normal operation
│ (failures exceed threshold)
▼
[Open] → Fail fast (don't call failing service)
│ (timeout expires)
▼
[Half-Open] → Try single request
│ success → [Closed]
│ failure → [Open]
Bulkhead Isolation:
Timeout and Retry:
Rate Limiting and Backpressure:
Saga Pattern:
Choreography: Services react to events
Order Service → OrderCreated event
Payment Service → listens → PaymentProcessed event
Inventory Service → listens → InventoryReserved event
(Compensating: if payment fails → InventoryReleased event)
Orchestration: Central coordinator
Saga Orchestrator:
1. Call Order Service
2. Call Payment Service
3. Call Inventory Service
(If step fails → call compensating transactions in reverse)
Event Sourcing:
CQRS (Command Query Responsibility Segregation):
Client-Side Discovery:
Server-Side Discovery:
Service Mesh:
Cache-Aside (Lazy Loading):
Read:
1. Check cache → hit? return
2. Miss? Query database
3. Store in cache, return
Write-Through:
Write:
1. Write to cache
2. Cache writes to database synchronously
3. Return success
Write-Behind (Write-Back):
Write:
1. Write to cache
2. Return success
3. Cache writes to database asynchronously (batched)
Cache Invalidation:
Decision Tree:
├─ Money involved? → Strong Consistency
├─ Double-booking unacceptable? → Strong Consistency
├─ Causality important (chat, edits)? → Causal Consistency
├─ Read-heavy, stale tolerable? → Eventual Consistency
└─ Default? → Eventual (then strengthen if needed)
├─ Single region writes? → Leader-Follower
├─ Multi-region writes + conflicts OK? → Multi-Leader
├─ Multi-region writes + no conflicts? → Leader-Follower with failover
└─ Maximum availability? → Leaderless (quorum)
├─ Need range scans? → Range Partitioning (risk: hot spots)
├─ Data residency requirements? → Geographic Partitioning
└─ Default? → Hash Partitioning (consistent hashing)
| System | If Partition | Else (Normal) | Use Case |
|------------|--------------|---------------|--------------------|
| Spanner | PC | EC (strong) | Global SQL |
| DynamoDB | PA | EL (eventual) | High availability |
| Cassandra | PA | EL (tunable) | Wide-column store |
| MongoDB | PC | EC (default) | Document store |
| Cosmos DB | PA/PC | EL/EC (5 levels) | Multi-model |
| Use Case | Consistency Model |
|----------------------------|------------------------|
| Bank account balance | Strong (Linearizable) |
| Seat booking (airline) | Strong (Linearizable) |
| Inventory stock count | Strong or Bounded |
| Shopping cart | Eventual |
| Product catalog | Eventual |
| Collaborative editing | Causal |
| Chat messages | Causal |
| Social media likes | Eventual |
| DNS records | Eventual |
| Configuration | W | R | N | Consistency | Use Case |
|--------------|---|---|---|-------------|-------------|
| Strong | 3 | 3 | 5 | Strong | Banking |
| Balanced | 3 | 2 | 5 | Strong | Default |
| Write-heavy | 2 | 3 | 5 | Strong | Logs |
| Read-heavy | 3 | 1 | 5 | Eventual | Cache |
| Max Avail | 1 | 1 | 5 | Eventual | Analytics |
For comprehensive coverage of specific topics, see:
Complete, runnable examples demonstrating patterns:
Visual representations for complex concepts:
Related Skills:
For Kubernetes deployment: See kubernetes-operations skill for pod anti-affinity, service mesh
For infrastructure: See infrastructure-as-code skill for deploying distributed systems
For databases: See databases-sql and databases-nosql for replication configuration
For messaging: See message-queues skill for event-driven architectures, saga orchestration
For monitoring: See observability skill for distributed tracing, monitoring patterns
For testing: See performance-engineering skill for load testing distributed systems
For security: See security-hardening skill for mTLS, service authentication
1. Choose replication: Multi-leader or Leaderless
2. Partition data geographically
3. Implement conflict resolution (LWW, vector clocks, app-specific)
4. Monitor replication lag
5. Add circuit breakers between datacenters
1. Define saga steps and compensating actions
2. Choose choreography (events) or orchestration (coordinator)
3. Implement idempotent handlers (retries safe)
4. Publish events with outbox pattern (transactional)
5. Monitor saga progress and timeouts
1. Use leaderless replication (N=5, W=3, R=2)
2. Partition with consistent hashing
3. Add circuit breakers for failing nodes
4. Implement read repair and anti-entropy
5. Monitor quorum health
Design for Failure:
Choose Consistency Carefully:
Idempotency is Critical:
Monitor and Observe:
Partition Strategically:
Version Everything:
Distributed Monolith:
Two-Phase Commit (2PC) Overuse:
Ignoring Network Failures:
Strong Consistency Everywhere:
No Conflict Resolution Strategy:
Cache Stampede:
Replication Lag Too High:
Split-Brain Scenario:
Hot Partitions:
Saga Timeout/Stalled:
Conflict Resolution Failures:
Integration with protocols.io API for managing scientific protocols. This skill should be used when working with protocols.io to search, create, update, or publish protocols; manage protocol steps and materials; handle discussions and comments; organize workspaces; upload and manage files; or integrate protocols.io functionality into workflows. Applicable for protocol discovery, collaborative protocol development, experiment tracking, lab protocol management, and scientific documentation.
Analyzes job descriptions and generates tailored resumes that highlight relevant experience, skills, and achievements to maximize interview chances
Generate Excalidraw diagrams from natural language descriptions. Use when asked to "create a diagram", "make a flowchart", "visualize a process", "draw a system architecture", "create a mind map", or "generate an Excalidraw file". Supports flowcharts, relationship diagrams, mind maps, and system architecture diagrams. Outputs .excalidraw JSON files that can be opened directly in Excalidraw.
Build and distribute Expo development clients locally or via TestFlight
Use when you have a written implementation plan to execute in a separate session with review checkpoints
Data structure for annotated matrices in single-cell analysis. Use when working with .h5ad files or integrating with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.
Benchling R&D platform integration. Access registry (DNA, proteins), inventory, ELN entries, workflows via API, build Benchling Apps, query Data Warehouse, for lab data management automation.
Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.
Take ancoleman/designing-distributed-systems from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.