I am doing research on how databases are designed internally. I found that there are three main components
- WAL - Write ahead log
- Memtable - In-memory data structure say RedBlack Tree or SkipList
- SSTables - Files on the disk
Now consider a database like cassandra
, it has sequential writes so there are no issues in updating the memtable
. However suppose if a write
and read
are coming at the same time then how does database like cassandra
works.
I am asking this because - suppose database is using the ReadBlack
tree as memtable and it starts write
which may cause the tree restructuring but at the same time read
is also happening then its can cause inconsistencies.
Another case, suppose if database is getting the lock
on redblacktree
before any write then it would be huge performance degradation as there could be 1000s of read waiting for the lock to release.
Can someone help with on how does it work,