Database / Apache Cassandra Intermediate and Advanced interview questions
Explain the write path in Cassandra?
A write in Cassandra is optimized to be fast and durable without doing any disk seeks or read-before-write checks.
flowchart LR A[Client sends write] --> B[Coordinator node] B --> C[Commit Log - append only, durability] B --> D[Memtable - in-memory, per table] D -->|threshold reached| E[Flush to SSTable on disk] C -.-> F[Replayed on crash recovery]
- The client sends the write to any node, which becomes the coordinator for that request.
- The coordinator forwards the write to all replicas that own the partition, based on the token ring.
- Each replica appends the mutation to its local commit log first, purely for crash recovery.
- The same mutation is applied to an in-memory memtable, sorted by clustering key.
- The coordinator waits only for the number of acknowledgements required by the requested consistency level before replying to the client.
- Later, once the memtable fills up, it is flushed to an immutable SSTable on disk, and the corresponding commit log segment can be discarded.
Because writes are just an append plus a sorted in-memory insert, Cassandra can sustain very high write throughput compared to databases that read existing rows first or update in place.
More Related questions...