Distributed Computing Mid
Explain the Two Generals Problem. Why can two nodes never be 100% certain they have reached a common agreement over an unreliable network?
Select the correct answer
One node may behave maliciously, so trust between the two parties can never be established.
Every message including acknowledgments can be lost, so no finite exchange guarantees mutual certainty.
Network latency varies widely, so the two nodes cannot synchronize clocks to act at once.
Messages can arrive out of order, so the two nodes cannot agree which attack time is correct.
What is the difference between synchronous and asynchronous communication models in distributed systems, and what are the trade-offs?
Select the correct answer
Asynchronous callers block for a reply, giving low latency; synchronous sends to a broker for higher resilience.
Synchronous callers block for a reply, giving simplicity but tight coupling; async decouples at the cost of complexity.
Synchronous callers use many threads, giving parallelism but high memory; async uses one thread with lower throughput.
Synchronous callers never wait for replies, giving speed; async always waits, giving guaranteed ordering and delivery.
Why do stateless services scale more easily than stateful ones, and how do we handle state when scaling horizontally?
Select the correct answer
They replicate session data to every node, so requests route freely; state stays cached inside each instance.
They store all state on the client only, so servers coordinate; state is synchronized between nodes on write.
They keep no local session data, so any instance serves any request; state is externalized to shared stores.
They pin each client to one node, so requests are sticky; state is held in local server memory only.
Explain 'Read-Your-Writes' consistency. How would you implement it in a system with asynchronous replication?
Select the correct answer
After a client writes a value, its own later reads always reflect that write; route the client's reads to replicas that have its last write.
Writes issued by one client are applied in the same order at every replica; push all writes through a single ordered global queue to enforce this.
After any write anywhere, every client immediately sees the newest value; make all replicas synchronously acknowledge each write before returning.
A client always observes the most recent write made by other clients; lock each record during reads so no concurrent update is missed here.
Explain the trade-off between Latency and Consistency in a system that is not currently experiencing a network partition.
Select the correct answer
Even without a partition, stronger consistency needs replica coordination that adds latency, so you trade lower latency against weaker consistency.
Even without a partition, weaker consistency needs more coordination and adds latency, so you trade higher latency for stronger consistency guarantees.
Without a partition there is no trade-off, since replicas are reachable and can always return strongly consistent reads with no extra latency cost.
Without a partition the only trade-off is durability versus latency, because consistency is guaranteed automatically whenever all nodes are online.
What is the difference between Linearizability and Eventual Consistency? When is Eventual Consistency 'not enough'?
Select the correct answer
Linearizability makes reads see the newest write in real time; eventual only guarantees convergence; eventual fails when stale reads cause wrong behavior.
Linearizability and eventual both prevent stale reads but differ in cost; eventual fails only when write throughput exceeds the cluster's replication limit.
Linearizability only guarantees eventual convergence; eventual guarantees real-time recency; eventual fails when replicas are allowed to diverge for too long.
Linearizability orders transactions while eventual orders single writes; eventual fails when a system needs multi-object serializable isolation guarantees.
What are monotonic reads and monotonic writes consistency, and what anomalies do they prevent?
Select the correct answer
Monotonic reads prevent seeing older data after newer; monotonic writes keep a process's writes ordered.
Monotonic reads ensure the latest write is always read; monotonic writes prevent two clients writing the same key.
Monotonic reads guarantee all replicas return identical values; monotonic writes force every node to write synchronously.
Monotonic reads block reads during writes; monotonic writes serialize all writes across the entire cluster globally.
Explain the CAP theorem. In a real-world network partition, why is it technically impossible to choose both Consistency and Availability? Can you give an example of a 'CP' vs. an 'AP' system?
Select the correct answer
During a partition writes are queued and replayed later, giving both C and A; DynamoDB is CP while etcd is an AP system example.
During a partition you can keep both if replication is fast enough; MongoDB is CP while Redis stays fully AP by default here.
During a partition nodes cannot sync, so you either reject requests (CP) or serve stale data (AP); ZooKeeper is CP, Cassandra AP.
During a partition consistency stays automatic, so the only real choice is between availability and partition tolerance; HBase is AP.
What is a 'Quorum' in a distributed system, and how do the values of N, R, and W affect consistency and availability?
Select the correct answer
N is the number of reads, R and W the retry counts; smaller values always improve both consistency and availability at once.
N is the write count, R and W the read and node totals; balancing them has no effect on consistency, only throughput limits.
N is the total nodes, R and W the replication delays; only W affects consistency while R alone controls cluster availability.
N is the number of replicas, R and W the nodes needed per read or write; larger R and W favor consistency over availability.
Explain the relationship R + W > N. If I want to increase read throughput in a distributed database, how should I tune these variables, and what is the trade-off regarding consistency?
Select the correct answer
Lower R and raise W for faster reads; but if R + W ≤ N you can lose the strong-consistency guarantee.
Lower both R and W for faster reads; consistency is unaffected because the overlap between replicas is always preserved anyway.
Raise R and lower W for faster reads; this keeps strong consistency while also making every single write far cheaper to perform.
Raise both R and W for faster reads; the only trade-off is extra storage cost, with no real impact on read consistency at all.
Why is 'Partition Tolerance' generally considered non-negotiable in distributed systems?
Select the correct answer
Networks inevitably drop or delay messages, so partitions will happen and cannot be prevented, systems must tolerate them.
Modern data-center networks are reliable enough that partitions are rare, but tolerance is kept purely for regulatory compliance needs.
Partition tolerance is what makes replication possible, so without it a system could never store more than one copy of any data.
Partition tolerance guarantees consistency and availability together, so dropping it would break both of the other properties at once.
What is the Byzantine Generals Problem, and how does it differ from a simple 'fail-stop' or 'crash' failure? When would a software engineer actually need to care about Byzantine Fault Tolerance (BFT)?
Select the correct answer
Byzantine nodes may act arbitrarily or maliciously, unlike crash faults where nodes simply stop; BFT matters in trustless systems like blockchains.
Byzantine faults are just slow nodes, unlike crash faults that go silent; BFT matters mainly when tuning timeouts in a local cluster network.
Byzantine faults occur only on disk, unlike crash faults on the network; BFT matters when checksumming files inside a single-machine database.
Byzantine faults are recoverable restarts, unlike permanent crash faults; BFT matters whenever replicas need to elect a leader among themselves.
What is graceful degradation, and how does a distributed system stay partially functional when components fail?
Select the correct answer
The system keeps core features running at reduced capability instead of failing entirely
The system shuts down cleanly to preserve data integrity whenever a critical component fails
The system replicates all data synchronously so that no functionality is ever lost in a failure
The system automatically restarts failed components to restore full service before users notice
Explain how Consistent Hashing works. How does it minimize data movement when a node is added or removed compared to a simple hash(key) mod N approach?
Select the correct answer
Consistent hashing rehashes every key with a new modulus, spreading them uniformly across all nodes
With mod N, adding a node remaps only one key while consistent hashing remaps every key evenly
Consistent hashing stores several copies of each key, so removing a node ends up moving no data at all
Keys and nodes map onto a ring, so only keys near the changed node move rather than nearly all keys
What are Virtual Nodes in consistent hashing, and what problem do they solve regarding data distribution?
Select the correct answer
Each virtual node caches frequently accessed keys in memory to reduce latency for hot partitions
Each virtual node replicates a key to several physical machines to fully guarantee fault tolerance
Each server takes a single ring position so the hash ring stays small, simple, and easy to reason
Each physical node maps to many ring points, evening out load and avoiding uneven distribution
What are the trade-offs between synchronous and asynchronous replication? If you choose 'Semi-synchronous' replication, what failure scenario are you trying to protect against?
Select the correct answer
It waits for all of the replicas to acknowledge, protecting against a network partition splitting the cluster
It sends writes to no replicas until much later, protecting against slow disks on the backup follower nodes
It waits for at least one replica to acknowledge, protecting against data loss if the primary crashes
It writes only to the primary and defers replicas, protecting against read overload on the follower nodes
Explain the difference between Leader-based, Multi-leader, and Leaderless replication.
Select the correct answer
Leader-based allows writes anywhere; multi-leader forbids writes entirely; leaderless routes all writes through one fixed node
Leader-based sends writes to one node; multi-leader accepts writes at several needing conflict resolution; leaderless uses quorums
Leader-based uses quorum writes; multi-leader routes reads through one node; leaderless never has to resolve any conflicts
Leader-based and multi-leader both funnel writes to a single node; leaderless replicates only reads by way of quorum voting
What is the difference between Range Partitioning and Hash Partitioning, and what are the tradeoffs regarding range queries vs. load balancing?
Select the correct answer
Both range and hash partitioning preserve key order equally well, so the only real difference lies in how they handle node failures.
Range partitioning keeps keys sorted for fast range scans but can create hotspots, while hash spreads load evenly yet scatters ranges.
Range partitioning always balances load better than hash, while hash is chosen only when strong consistency across shards is required.
Hash partitioning keeps keys sorted for fast range scans but can create hotspots, while range spreads load evenly yet scatters ranges.
What is data rebalancing when partitions are added or removed, and what strategies avoid moving too much data at once?
Select the correct answer
Rebalancing pauses the cluster to redistribute data evenly; assigning one giant partition per node lets the system move data without any downtime.
Rebalancing rewrites every key's hash when nodes change; hashing modulo the node count keeps movement minimal and avoids remapping most of the keys.
Rebalancing shifts partitions when nodes join or leave; using fixed partitions or consistent hashing moves only a small fraction rather than everything.
Rebalancing duplicates all partitions onto new nodes on any change; snapshotting the whole dataset first ensures only recent writes need to move.
How does a request get routed to the correct partition or shard, and what are the trade-offs between different routing approaches?
Select the correct answer
A DNS lookup alone decides the target partition for every key; this keeps clients simple but requires rehashing the entire keyspace whenever nodes change.
Requests are always broadcast to every partition which then ignores irrelevant keys; this avoids routing metadata but wastes bandwidth on each request.
A client, a routing proxy, or any contacted node can map keys to partitions; each choice trades where routing logic lives against extra hops and coupling.
Only a central coordinator can map keys to partitions; this removes all extra hops but tightly couples clients and forces them to cache the full topology.
What is a Lamport Clock, and how does it differ from a Vector Clock? What specific problem do Vector Clocks solve that Lamport Clocks cannot?
Select the correct answer
Lamport clocks need synchronized physical clocks whereas vector clocks do not need any.
Vector clocks can detect whether two events are concurrent, which Lamport clocks cannot.
Vector clocks reduce message overhead by storing just a single integer per node event.
Lamport clocks guarantee a total event ordering while vector clocks give only partial order.
Explain the 'Happens-Before' relationship. How do we determine if two events are concurrent?
Select the correct answer
Two events are concurrent if one causally depends on the other through a message.
Two events are concurrent if they occur at the same physical wall-clock time value.
Two events are concurrent if neither one happens-before the other in the ordering.
Two events are concurrent if they happen to share the same Lamport timestamp number.
Why can't we rely on physical system clocks (NTP) for ordering events in a distributed system? What is 'clock skew' and how does it affect distributed logs?
Select the correct answer
Clock skew only affects a single local machine and never the event ordering across nodes.
Physical clocks are strictly monotonic, so under load they simply overcount logged events.
Physical clocks drift and differ between nodes, so their timestamps cannot reliably order events.
NTP synchronizes clocks perfectly, but network latency alone reorders the log timestamps.
What is a Lamport Clock, and how does it allow us to determine the partial ordering of events without a synchronized physical clock?
Select the correct answer
It synchronizes all node counters to a single global value that is shared cluster-wide.
It assigns counters so that equal timestamps always imply the two events are concurrent.
It records the physical wall-clock time and rounds it down to the nearest logical tick.
It assigns counters so that if a happens-before b, then a's timestamp is less than b's.
What is Last-Write-Wins (LWW), and why is it dangerous in systems where physical clocks are not perfectly synchronized?
Select the correct answer
It requires a central coordinator that becomes a bottleneck under any heavy write load.
It always keeps both conflicting values, forcing the application to merge them by hand.
A skewed clock can give an older write a higher timestamp, so it overwrites a newer write.
It orders writes by arrival at the server, silently dropping the update that came first.
Explain the concept of 'Clock Skew' and its impact on distributed transaction ordering.
Select the correct answer
It is the gradual slowing of one clock over time, which duplicates transaction identifiers.
It is the delay of network packets, which forces transactions to be retried repeatedly.
It is the drift of a single clock, which affects only local reads and never global commits.
It is the difference between clocks on nodes, which can misorder timestamp-based transactions.
Explain how a Lamport Clock works. If two events have the same Lamport timestamp, can we determine which one happened first? Why or why not?
Select the correct answer
A counter increments per event and travels with messages; equal timestamps mean the events occurred simultaneously in real wall-clock time.
A counter increments per event and travels with messages; equal timestamps mean one event definitely happened-before the other one.
A counter increments per event and travels with messages; equal timestamps mean the events are concurrent and cannot be ordered.
A counter increments per event and travels with messages; equal timestamps let us break ties using each node's unique process identifier.
How do Vector Clocks allow us to detect 'causal' relationships between events? In what scenario would a Vector Clock show that two writes are 'concurrent' or 'conflicting'?
Select the correct answer
Each node tracks a per-node counter vector; two writes are concurrent when neither vector is fully greater-or-equal to the other.
Each node tracks a per-node counter vector; two writes are concurrent when the summed totals of both vectors happen to match.
Each node tracks a per-node counter vector; two writes conflict only when both vectors are exactly identical in every position.
Each node tracks a per-node counter vector; two writes conflict when one vector is strictly greater than the other one.
What is 'Replication Lag,' and what specific anomalies can a user see because of it? How would you design a system to prevent a user from seeing their own update disappear after a refresh?
Select the correct answer
Delay between leader and replica updates; a user may miss their own write, fixed by caching every read response indefinitely on the client side.
Delay between leader and replica updates; a user may miss their own write, fixed by disabling all replicas and reading only the leader always.
Delay between leader and replica updates; a user may miss their own write, fixed by routing reads to an up-to-date replica after writing.
Delay between leader and replica updates; a user may miss their own write, fixed by adding more replicas so lag is spread across many nodes.
What are the practical risks of Eventual Consistency? How do concepts like 'Read-your-writes' or 'Monotonic Reads' help mitigate the poor user experience of eventual consistency?
Select the correct answer
Stale reads are the risk; read-your-writes ensures you see others' updates and monotonic reads prevents two reads returning same value.
Stale reads are the risk; read-your-writes ensures you see your own updates and monotonic reads prevents reads going backward in time.
Stale reads are the risk; read-your-writes replicates data synchronously and monotonic reads discards older versions of data permanently.
Stale reads are the risk; read-your-writes forces every node to lock and monotonic reads guarantees strict global ordering of all writes.
What are the trade-offs of Eventual Consistency, and how does a system eventually converge if multiple nodes receive conflicting updates?
Select the correct answer
It trades consistency for availability and low latency; conflicting updates converge via resolution rules like last-write-wins or CRDTs.
It trades partition tolerance for consistency; conflicting updates converge by pausing the system until an administrator resolves them.
It trades availability for strong consistency; conflicting updates converge by rejecting all but the first write that any node received.
It trades latency for durability guarantees; conflicting updates converge by requiring a quorum to vote on every single write operation.
Explain the high-level roles in the Raft consensus algorithm (Leader, Follower, Candidate). How does the system ensure that two leaders are never elected for the same term?
Select the correct answer
Followers elect one Candidate per term; a candidate needs a majority of votes, and each node votes once, so two leaders can't win a term.
Followers elect one Candidate per term; a candidate needs unanimous votes from all nodes, each voting once, so two leaders can't win a term.
Followers elect one Candidate per term; a candidate needs the highest node ID, and ties break randomly, so two leaders can't win a term.
Followers elect one Candidate per term; a candidate needs approval from the previous leader, which steps down, so two leaders can't win.
What is 'Leader Election', and what happens to a distributed system when the leader becomes partitioned from the followers?
Select the correct answer
Choosing one node to coordinate; if it is partitioned, both sides keep their leaders and freely commit writes independently.
Choosing one node to coordinate; if it is partitioned, followers time out and elect a new leader while the old one is isolated.
Choosing one node to coordinate; if it is partitioned, the whole cluster halts until the original leader rejoins the network.
Choosing one node to coordinate; if it is partitioned, followers promote themselves so every node becomes its own leader.
How do heartbeats and election timeouts work together in a consensus protocol? What happens if the election timeout is set too low or too high?
Select the correct answer
Heartbeats sync clocks between nodes; too low drifts the clocks apart, too high causes two duplicate leaders to be elected at once.
Leaders send heartbeats to reset follower timers; too low causes needless elections, too high delays detecting a failed leader.
Followers send heartbeats to the leader to reset timers; too low wastes bandwidth, too high blocks new clients from connecting.
Heartbeats commit log entries while timeouts trigger snapshots; too low corrupts the log, too high exhausts available disk space.
What are the different message ordering guarantees, FIFO, causal, and total order, and when does each matter?
Select the correct answer
FIFO orders all messages globally, causal orders per sender, total respects causality only.
FIFO and causal both give one global order, while total order only tracks per-sender order.
FIFO preserves per-sender order, causal respects happens-before, total gives one global order.
FIFO respects happens-before, causal preserves per-sender order, total relies on timestamps.
Why is Idempotency critical in distributed systems, and how would you design an idempotent API?
Select the correct answer
Retries can duplicate requests, so an idempotency key lets the server dedupe repeated calls.
Networks drop packets, so caching every response forever guarantees identical repeated results.
Servers can crash, so wrapping each request in a distributed lock prevents all duplicate effects.
Clients may reorder calls, so sequence numbers force the server to process requests in order.
Explain the Two-Phase Commit (2PC) protocol. What is its biggest blocking weakness if the coordinator fails?
Select the correct answer
If the coordinator fails during commit, participants automatically elect a new coordinator instantly.
If the coordinator fails after prepare, participants keep locks and block until it recovers.
If the network partitions, participants each unilaterally abort, causing inconsistent partial commits.
If a participant fails during prepare, the coordinator silently commits without its acknowledgment.
What is the Saga pattern, and how does it maintain data consistency without using a distributed lock?
Select the correct answer
It holds a global lock across every service so all local transactions commit or roll back together.
It splits work into local transactions, each with a compensating action that undoes it on failure.
It uses a coordinator that votes with all nodes before permanently committing any local transaction step.
It queues all writes centrally and replays them in order so no two services ever conflict at once.
Explain the difference between 'At-least-once', 'At-most-once', and 'Exactly-once' delivery guarantees.
Select the correct answer
At-least-once never loses or duplicates; at-most-once can duplicate; exactly-once may lose some messages occasionally.
At-least-once always duplicates messages; at-most-once always loses some; exactly-once simply retries until acknowledged.
At-least-once can lose but never duplicates; at-most-once can duplicate but never loses; exactly-once does neither.
At-least-once can duplicate but never loses; at-most-once can lose but never duplicates; exactly-once does neither.
What is the Transactional Outbox pattern, and how does it solve the problem of atomically updating a database and sending a message to another system?
Select the correct answer
It caches the message in memory and retries publishing it until the database transaction is fully committed.
It sends the message first and only commits the database write after the broker confirms delivery success.
It wraps the database write and the broker publish inside one distributed two-phase commit spanning both.
It writes the message to an outbox table in the same transaction, then a relay publishes it separately.
Explain the Gossip (Epidemic) Protocol. How does it allow a cluster of thousands of nodes to maintain a membership list without a central registry?
Select the correct answer
Each node periodically exchanges state with a few random peers, so updates spread exponentially across the whole cluster.
Every node continuously multicasts its full state to all other nodes so the cluster converges instantly on any change.
A designated registry node broadcasts membership updates to every peer at fixed intervals to keep all of them synchronized.
Nodes elect a leader that keeps the authoritative list and pushes deltas down a spanning tree to all of its followers.
What is the 'Split Brain' problem, and how do quorums and fencing tokens prevent it?
Select the correct answer
A memory leak splits a node's heap into stale data; quorums cache the majority value and fencing tokens later purge it out.
A partition lets two sides both act as leader; quorums require a majority to act and fencing tokens reject stale writers.
A slow disk creates duplicate log entries on a node; quorums deduplicate the writes and fencing tokens compress the logs.
A clock skew makes two nodes disagree on time; quorums resynchronize the clocks and fencing tokens timestamp every message.
What is failover, and how does a system detect failure and promote a standby without causing inconsistency?
Select the correct answer
A standby continuously mirrors writes and takes over instantly; because replication is synchronous, no inconsistency can arise.
A load balancer reroutes traffic on failure automatically; since clients retry idempotently, leader consensus is unnecessary.
A standby is promoted once failure is detected; quorums and fencing prevent two active primaries from diverging their state.
A standby is promoted on any single missed heartbeat at once; a shared timestamp guarantees the old primary rejects all writes.
What is service discovery, and why is it a coordination problem in dynamic distributed systems?
Select the correct answer
It caches DNS records locally on each client node; because addresses stay static, no coordination between services is ever needed.
It load-balances requests across fixed backend servers; the registry rarely changes, so simple config files handle it without help.
It maps service names to current instance locations; endpoints change constantly, so keeping the registry consistent is coordination.
It assigns permanent IP addresses to each microservice; since the locations never move, discovery is purely a naming convention.
What is the coordinator/worker (master/worker) pattern, and what are the risks of having a single coordinator?
Select the correct answer
A coordinator only stores results while workers self-assign tasks; its failure merely delays reporting but never stalls processing.
Workers coordinate peer-to-peer with no central role at all; the main risk is the high messaging overhead among many workers.
A coordinator assigns and tracks work across workers; it is a single point of failure and bottleneck unless made highly available.
Workers elect a coordinator each cycle to share load evenly; the main risk is workers duplicating tasks when the network is slow.
Explain the 'Thundering Herd' problem. How do jitter and exponential backoff help mitigate it?
Select the correct answer
Cache expiry floods the database; backoff shards the cache and jitter replicates hot keys across additional nodes to spread the pressure.
Simultaneous client retries overwhelm a resource; backoff lengthens gaps between attempts and jitter randomizes their timing.
A single slow client blocks others; backoff caches its responses and jitter deduplicates identical requests before they reach the server.
Nodes gossip too frequently; backoff compresses their messages and jitter batches them so total network bandwidth stays within safe limits.
Explain the MapReduce execution model. Why is 'Data Locality' a core principle of its design?
Select the correct answer
Mappers process splits in parallel and shuffle by key to reducers; running tasks where data resides avoids costly network transfer of inputs.
A master streams records to workers continuously; locality caches intermediate keys in memory so repeated jobs skip re-reading the data blocks.
Reducers read all input first then mappers aggregate by key; locality keeps every reducer's output on one node to simplify the final merge.
Mappers and reducers run on separate clusters via a queue; locality replicates code to all nodes so identical binaries execute the workload.
Explain 'Backpressure'. Why is it critical for a downstream service to signal its inability to keep up with requests?
Select the correct answer
It lets a fast upstream service push extra work downstream, keeping buffers full so the slower consumer never sits idle during traffic bursts.
It lets an overloaded downstream service signal upstream to slow down, preventing queue buildup, resource exhaustion, and cascading failure.
It duplicates requests across downstream replicas, ensuring at least one copy is processed even when a single consumer node becomes overloaded.
It compresses requests before sending them downstream, cutting bandwidth so the consumer can process larger batches within its memory budget.
What is a distributed file system like GFS or HDFS at a conceptual level, and how does it achieve fault tolerance for large data?
Select the correct answer
Files are striped across nodes without copies, and lost blocks are recomputed from parity kept on a single dedicated metadata master node.
Each client caches the entire file locally and periodically syncs edits, so a node crash is recovered from the caches of connected clients.
Large files are split into blocks spread across many machines, each block replicated on multiple nodes so data survives individual failures.
Large files are kept whole on one powerful node and mirrored nightly to a backup, so a hardware failure loses at most a day of data.
Why do retries in a distributed system need backoff and jitter, and how can naive retries make an outage worse?
Select the correct answer
Naive retries block the client thread forever; backoff runs attempts in parallel and jitter caps the concurrent connections each client may open.
Naive retries corrupt in-flight data; backoff rolls back the partial writes and jitter randomizes which write commits first among competing clients.
Naive immediate retries multiply load on a struggling service; backoff spaces attempts and jitter desynchronizes clients to avoid retry storms.
Naive retries drop the original request; backoff resends it to another region and jitter picks that region randomly to balance total load evenly.