Protocol & Design Interview Questions - Hard
Hard-level protocol and design interview questions covering advanced distributed systems and protocol design.
Q1: Design a custom protocol for real-time multiplayer gaming.
Answer:
Protocol Design
Message Format
Header Fields:
- Magic Number: Protocol identifier
- Version: Protocol version
- Flags: Reliable, ordered, encrypted
- Sequence: For ordering and deduplication
- Timestamp: For latency calculation
- Message Type: Action, state, event
- Player ID: Source player
- Payload: Message-specific data
Client-Server Architecture
Key Techniques:
- Client Prediction: Immediate feedback
- Server Reconciliation: Correct mispredictions
- Lag Compensation: Rewind time for hit detection
- Delta Compression: Send only changes
- Interest Management: Only send relevant updates
Q2: Explain Byzantine Fault Tolerance and PBFT.
Answer:
Byzantine Generals Problem
PBFT (Practical Byzantine Fault Tolerance)
PBFT Protocol Flow
Requirements:
- N β₯ 3f + 1: To tolerate f Byzantine faults
- Quorum: 2f + 1 nodes must agree
- View Change: Replace faulty primary
Use Cases:
- Blockchain consensus (Hyperledger Fabric)
- Distributed databases
- Critical infrastructure
Q3: Design a distributed lock service (like Chubby/ZooKeeper).
Answer:
Architecture
Lock Acquisition
Session Management
Lock Types
Features:
- Advisory Locks: Clients cooperate
- Fencing Tokens: Prevent stale lock holders
- Watch Mechanism: Notify on lock release
- Lock Queuing: Fair ordering
Fencing Token:
Q4: Explain distributed transactions and 2PC/3PC.
Answer:
Two-Phase Commit (2PC)
2PC Protocol
2PC Failure Scenario
2PC Problems:
- Blocking: If coordinator fails after prepare
- Single point of failure: Coordinator
- Not partition tolerant
Three-Phase Commit (3PC)
3PC Advantages:
- Non-blocking (with timeout)
- Can make progress during coordinator failure
3PC Disadvantages:
- More complex
- More latency
- Still not partition tolerant
Saga Pattern (Alternative)
Saga: Sequence of local transactions with compensating actions
Q5: Design a content delivery network (CDN) protocol.
Answer:
CDN Architecture
Request Flow
Cache Invalidation
Purge Protocol:
Cache Hierarchy
Advanced Features:
- Anycast: Same IP, routed to nearest POP
- Dynamic Content: Edge compute (Cloudflare Workers)
- Image Optimization: On-the-fly resizing
- DDoS Protection: Absorb attacks at edge
Q6: Explain QUIC protocol and HTTP/3.
Answer:
TCP vs QUIC Handshake
Head-of-Line Blocking
Connection Migration
QUIC Benefits:
- Faster connection establishment
- Better performance on lossy networks
- Improved mobile experience
- Easier to deploy (UDP not blocked)
Q7: Design a gossip protocol for distributed systems.
Answer:
Gossip Algorithm
Information Spread
Gossip Variants
Anti-Entropy
Use Cases:
- Cluster membership (Consul, Cassandra)
- Failure detection
- Database replication
- Configuration propagation
Trade-offs:
- Pros: Scalable, fault-tolerant, simple
- Cons: Eventually consistent, message overhead, convergence time
Q8: Explain vector clocks and conflict resolution.
Answer:
Vector Clock Structure
Format: [A:3, B:1, C:2] = A has seen 3 events from A, 1 from B, 2 from C
Vector Clock Evolution
Conflict Detection
Comparison Rules:
- V1 < V2: All counters in V1 β€ V2, at least one <
- V1 > V2: All counters in V1 β₯ V2, at least one >
- V1 || V2: Neither < nor >
Conflict Resolution
Example - Shopping Cart:
Use Cases:
- Dynamo-style databases (Riak, Cassandra)
- Collaborative editing
- Distributed caches
- Mobile offline-first apps
Q9: Design a distributed rate limiter.
Answer:
Architecture Options
Centralized Approach
Pros: Accurate, simple Cons: Single point of failure, latency
Distributed with Gossip
Pros: No single point, scalable Cons: Eventually consistent, may exceed limit temporarily
Token Bucket with Redis
Lua Script (atomic):
1local key = KEYS[1]
2local capacity = tonumber(ARGV[1])
3local rate = tonumber(ARGV[2])
4local now = tonumber(ARGV[3])
5
6local last_refill = redis.call('HGET', key, 'last_refill') or now
7local tokens = redis.call('HGET', key, 'tokens') or capacity
8
9local elapsed = now - last_refill
10local new_tokens = math.min(capacity, tokens + elapsed * rate)
11
12if new_tokens >= 1 then
13 redis.call('HSET', key, 'tokens', new_tokens - 1)
14 redis.call('HSET', key, 'last_refill', now)
15 return {new_tokens - 1, 1}
16else
17 return {new_tokens, 0}
18end
Sliding Window with Redis
Trade-offs:
- Accuracy: Centralized > Hybrid > Distributed
- Latency: Distributed < Hybrid < Centralized
- Scalability: Distributed > Hybrid > Centralized
Q10: Explain consensus in blockchain (Proof of Work, Proof of Stake).
Answer:
Proof of Work (Bitcoin)
Mining Process: $$\text{SHA256}(\text{SHA256}(\text{block header})) < \text{target}$$
PoW Characteristics:
- Security: 51% attack expensive
- Decentralized: Anyone can mine
- Energy: High consumption
- Finality: Probabilistic (6 confirmations)
Proof of Stake (Ethereum 2.0)
Validator Selection
PoS Characteristics:
- Energy: Low consumption
- Security: Slashing for misbehavior
- Finality: Faster (2 epochs β 13 minutes)
- Barrier: Need stake to participate
Slashing
Comparison
Use Cases:
- PoW: Bitcoin, Litecoin, Monero
- PoS: Ethereum 2.0, Cardano, Polkadot
- DPoS: EOS, Tron
- PoA: Private blockchains
Summary
Hard protocol and design topics:
- Game Protocol: Low latency, client prediction, lag compensation
- Byzantine Fault Tolerance: PBFT, 3f+1 nodes
- Distributed Locks: Chubby/ZooKeeper, fencing tokens
- Distributed Transactions: 2PC/3PC, Saga pattern
- CDN Protocol: Edge caching, invalidation, anycast
- QUIC/HTTP3: UDP-based, 0-RTT, connection migration
- Gossip Protocol: Epidemic spread, anti-entropy
- Vector Clocks: Causality tracking, conflict detection
- Distributed Rate Limiting: Token bucket, sliding window
- Blockchain Consensus: PoW, PoS, trade-offs
These advanced concepts enable designing complex distributed systems and protocols.
Related Snippets
- Protocol & Design Interview Questions - Easy
Easy-level protocol and design interview questions covering fundamental β¦ - Protocol & Design Interview Questions - Medium
Medium-level protocol and design interview questions covering advanced β¦ - Protocol Buffers Interview Questions - Easy
Easy-level Protocol Buffers interview questions covering basics, syntax, and β¦ - Protocol Buffers Interview Questions - Hard
Hard-level Protocol Buffers interview questions covering advanced topics, β¦ - Protocol Buffers Interview Questions - Medium
Medium-level Protocol Buffers interview questions covering advanced features, β¦