system design · advanced
System Design: NFRs, Critical Path, Architecture Patterns, LLD Framework
System design fundamentals. NFRs (Non-Functional Requirements): define HOW, not what; unmeasurable NFRs are invalid; latency < 1ms P99, throughput > 100K/sec, 99.99% uptime = valid NFRs. Critical path: sequence that must never fail; on critical path: no malloc/mutex/logging; lock-free + pre-allocated. Latency vs throughput: batching → throughput↑ latency↑; streaming → latency↓ throughput↓; pipeline with SPSC queues = both bounded. Architecture patterns by NFR: Layered=CRUD apps; Clean/Hexagonal=domain independence (testable); Event-driven=audit trail+replay+loose coupling (eventual consistency); Pipeline=C++ stream processing (market data, video); CQRS=separate read/write models; Microservices=large teams only (high operational overhead). Scalability: vertical=bigger machine (ceiling); horizontal=more instances (stateless required). LLD 5 steps: clarify NFRs → entities → interfaces → patterns → extensibility.
NFRs first: unmeasurable NFRs are invalid; identify critical path before designing; latency vs throughput trade-off (batching = throughput ↑, latency ↑); architecture: layered/clean/event-driven/pipeline/CQRS based on NFRs not trend; horizontal scale = stateless + externalized state.
The code
// System Design Concepts — NFRs, Scalability, Architecture Patterns
// NFR Examples for C++ / HFT systems:struct NFR { // Latency: < 1ms P99 (market data handler) // Throughput: > 100K events/sec // Availability: 99.99% (52 min downtime/year) // Reliability: zero message loss};
// Critical Path (Trading):// Market Data → Feed Handler → Strategy → Risk Check → Order Router → Exchange// Every step on critical path must be < 1ms; zero blocking calls
// Latency vs Throughput tradeoff:// Batching: group N requests → send together → HIGHER throughput, HIGHER latency// Streaming: send each immediately → LOWER latency, LOWER throughput
// Architecture selection matrix:// Low latency, tight control → Monolith / in-process pipeline// Audit trail, replay → Event-driven / event sourcing// Complex domain rules → Clean / Hexagonal architecture// Separate read/write perf → CQRS// Runtime swappable algorithms → Strategy pattern// Independent deployment scaling → Microservices (only if team is ready!)
// Pipeline pattern (C++ market data):// Stage 1: Decode raw bytes → Stage 2: Normalize ticks →// Stage 3: Strategy → Stage 4: Risk → Stage 5: Order// Each stage: dedicated thread + SPSC lock-free queue between stages
// CQRS — separate read/write models:// Command side: validates + writes (source of truth)// Query side: denormalized read model (fast reads, eventual consistency)// Event bus synchronizes write→read side asynchronously
// Scalability:// Vertical (scale-up): bigger machine; has ceiling; needs restart// Horizontal (scale-out): more instances behind LB; stateless required
// LLD approach (5 steps):// 1. Clarify requirements (functional + NFR)// 2. Identify core classes / entities// 3. Define interfaces (abstract, not concrete)// 4. Apply design patterns where they fit naturally// 5. Show extensibility: how to add new feature without breaking existingWhat this lesson walks through
- 01NFRs — the foundation of every architecture decision
- 02Critical Path — the sequence that must never fail
- 03Latency vs Throughput — the fundamental trade-off
- 04Architecture patterns — when to use each
- 05Scalability — vertical vs horizontal
- 06LLD interview approach — 5-step framework
Non-functional requirements (NFRs) define HOW a system performs, not what it does. They are the primary driver of architecture choices. The key rule: unmeasurable NFRs are invalid. 'Fast' is not an NFR. 'P99 latency < 1ms' is. NFRs constrain which architectures are even viable. Before choosing any pattern or framework, write down the NFRs and challenge every one: 'what breaks if we don't meet this?'
See it animated — step by step, at your own pace
Unlock the full interactive walkthrough of System Design: NFRs, Critical Path, Architecture Patterns, LLD Framework and 100+ animated C++ interview lessons.