CodeSignal Technical Assessment System Design and Architecture 3 — Questions and Answers
Question 1: In a distributed system, which CAP theorem combination is chosen by a system that remains available during a network partition but may return stale data?
- CP (Consistent and Partition-tolerant)
- CA (Consistent and Available)
- AP (Available and Partition-tolerant) (Correct answer)
- ACP (all three)
Correct answer: AP (Available and Partition-tolerant)
AP systems sacrifice strong consistency to remain available when partitions occur, returning possibly stale data instead of refusing requests.
Question 2: You need to aggregate 1 billion events per day into per-user daily counts. Which architecture is most cost-effective when results are only needed by morning?
- Real-time stream processing with Redis counters
- Batch MapReduce job running nightly (Correct answer)
- Synchronous OLTP database updates per event
- In-memory distributed cache with TTL
Correct answer: Batch MapReduce job running nightly
Nightly batch MapReduce processes the full dataset efficiently in bulk, which is far cheaper than real-time aggregation for non-latency-sensitive daily counts.
Question 3: What is the main purpose of a write-ahead log (WAL) in a database?
- Speeding up read queries
- Ensuring durability by logging changes before applying them (Correct answer)
- Compressing data on disk
- Distributing writes across shards
Correct answer: Ensuring durability by logging changes before applying them
The WAL records every change before it is applied to data pages, allowing recovery to a consistent state after a crash.
Question 4: An API gateway receives 50,000 requests/sec. Which rate-limiting algorithm smooths traffic most evenly without bursting?
- Token bucket
- Leaky bucket (Correct answer)
- Fixed window counter
- Sliding window log
Correct answer: Leaky bucket
The leaky bucket drains at a constant rate, enforcing a steady outflow regardless of incoming burst patterns.
Question 5: When sharding a database by user ID, which problem arises if a small number of users generate the vast majority of traffic?
- Referential integrity violations
- Hot shard (hotspot) imbalance (Correct answer)
- Cross-shard transaction deadlocks
- Index fragmentation
Correct answer: Hot shard (hotspot) imbalance
Hot shards occur when a few high-traffic keys land on the same shard, causing uneven load that negates sharding benefits.
Question 6: Which replication strategy ensures the lowest write latency in a distributed database cluster?
- Synchronous replication to all replicas before acknowledging
- Asynchronous replication — acknowledge after leader writes locally (Correct answer)
- Quorum writes (majority must confirm)
- Multi-master synchronous replication
Correct answer: Asynchronous replication — acknowledge after leader writes locally
Asynchronous replication acknowledges writes immediately after the leader persists them, without waiting for followers, minimizing write latency at the cost of potential data loss.
Question 7: A search feature must return results within 100ms for queries across 500 million documents. Which indexing approach is essential?
- Full table scan with parallel threads
- Inverted index (Correct answer)
- B-tree index on document body
- Column-store index
Correct answer: Inverted index
An inverted index maps terms to the documents containing them, enabling sub-millisecond keyword lookups across billions of documents.
In a distributed system, which CAP theorem combination is chosen by a system that remains available during a network partition but may return stale data?