← Back🌐

Foundations: The Pattern Playbook — Key Architecture Patterns

AWAKENING0 / 100
[░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░]0%

Foundations: The Pattern Playbook — Key Architecture Patterns

High Level Design·beginner·~25 min read

  • basics
  • patterns
  • scaling
  • async
  • contention
  • workflow

- Pushing Real-Time Updates - Handling Long-Running Tasks (Two Async Patterns) - Dealing with Contention - Scaling Reads (Natural Progression) - Scaling Writes - Distributed Key-Value Store Design - Unique ID Generation (Distributed) - H…

What you'll learn

  • Pushing Real-Time Updates

    Start simple → add complexity only when needed: - HTTP polling → SSE → WebSockets - Pub/Sub services for decoupling publishers/subscribers - Consistent hash ring for routing to stateful servers

  • Handling Long-Running Tasks (Two Async Patterns)

    - Web server validates request → pushes job to queue → returns job ID immediately - Separate workers execute tasks asynchronously - Don't use queues for short-running tasks — synchronous is simpler and provides better UX Pattern A — Defe…

  • Dealing with Contention

    - Start with database-level solutions (pessimistic/optimistic locking) - Move to distributed locks only when spanning multiple services - Queue-based serialization for ordering conflicting operations

  • Scaling Reads (Natural Progression)

    1. Optimize within DB (indexing, denormalization) 2. Read replicas for horizontal scale 3. External cache (Redis) for hot data 4. CDN for static/semi-static content

  • Scaling Writes

    - Horizontal sharding (choose partition key carefully) - Write queues to buffer spikes (Kafka) - Batching to reduce per-operation overhead - Load shedding for overload protection

  • Distributed Key-Value Store Design

    A fundamental building block for many systems. Key techniques: | Problem | Solution | |---------|----------| | Partitioning large datasets | Consistent hashing | | High availability reads | Replication + multi-datacenter | | Conflict res…

  • Unique ID Generation (Distributed)

    | Approach | Pros | Cons | |----------|------|------| | Auto-increment by K (multi-master) | Uses existing DB | Hard to scale, not time-sortable | | UUID (128-bit) | No coordination | Too long, not sortable | | Ticket server (centralized…

  • Handling Large Files

    - Presigned URLs: client uploads directly to blob storage (bypasses app servers) - CDN with signed URLs for downloads - Chunked/multipart upload for resumability

  • Multi-Step Processes

    - Range from simple orchestration to workflow engines (Temporal, Step Functions) - Event sourcing: each step emits events triggering subsequent steps - Key shift: "scattered state management" → "declarative workflow definitions"

  • Platform Layer (Separating Web from Logic)

    Instead of web servers talking directly to databases, introduce an intermediate platform/service layer: Three reasons to do this: 1. Independent scaling — web tier and platform tier scale separately. A new API endpoint means more platfor…

  • Scaling an Existing Microservice (100x Growth)

    A common interview question: "Your service handles 100 RPM today. How would you scale it to 10,000 RPM?" This tests systematic thinking about identifying and eliminating bottlenecks.

  • Methodology

  • Concrete Example: Scaling a Sign-Up Service

  • Scaling Decision Tree

    ---

  • Quick Problem Fixes

    Small, high-yield recipes for the problems interviewers love to probe and production teams hit weekly. Each entry states the failure mode, the pattern, real usage, and the gotcha. ---

  • Fix 1 — How to Prevent Double Payments (Idempotent Financial Operations)

    The failure mode. A client calls POST /payments, the server charges the customer, then the response is lost (client timeout, retry-happy proxy, mobile-network drop). The client retries. The customer is now charged twice. Common causes: -…

  • Fix 2 — Cross-System Transactions (Saga, Outbox, Idempotency + Ordering, TCC)

    The failure mode. You need to update two systems atomically: - Charge the customer (Payments service, MySQL). - Reserve inventory (Inventory service, DynamoDB). - Enqueue a shipping event (Kafka). The classic monolith answer — a database…

← back to High Level Design

Foundations: The Pattern Playbook — Key Architecture Patterns — High Level Design | GoCrack | GoCrack