Scenario: Types of Databases available based on requirements
Solution:
Two types of Database Indexes:
- LSM trees + SS Tables.
- Balanced binary tree in memory. When it gets big its pushed to disk (SS Table - Sorted list of keys).
- If there are many SS Table then they are merged.
- Fast writes to memory.
- For reads, one needs to search many SS Tables.
- B trees
- Binary trees using pointers on disk.
- Pages on disk with range of keys. Write iterates through the binary tree and either update an existing key value or create a new page on disk and modify pointer to the new page.
- Faster reads, as it knows where key is located.
- Slow write to disk.
Replication
- Single leader
- All writes to one master which replicates to others. Read from any.
- There are no conflicts.
- Can be mitigated with shards and partition.
- Multi leader
- Go to small subset of leader DBs. Read from any.
- Increase in write throughput but write conflicts could occur.
- Leaderless
- Write to all, read from any.
- Increase in write throughput but write conflicts could occur.
SQL Databases
- Relational/Normalized data.
- It requires 2 phase commits
- Check each node if it's able to promise to carry out the update
- Commit, actually write the data.
- If any node is unable to make that promise, then the coordinator tells all nodes to rollback, releasing any locks they have, and the transaction is aborted.
- ACID guarantees
- Slow due to #2. Transactions are slow.
- Use B trees.
- Relational database or RDBMS databases are vertically Scalable.
- Expensive.
Mongo DB
- Its document DBs. Documents can be nested.
- NoSql
- Use B trees and supports transactions.
- With NoSQL, unstructured & schema less data can be stored in multiple collections and nodes. It does not require fixed table schemas and it allows limited join queries, and can be scaled horizontally.
- Relatively cheaper.
- No Stored Procedure.
Apache Casandra
- No Sql
- Wide column data store (like excel spreadsheet)
- Shard key and Sort key
- Multileader/leaderless
- Fast writes. Quorum. Last write wins.
- Based on LSM & SS Tables.
- Good for high write volume and consistency not that vital. All write and reads go to same shard. Like chat application.
- No transaction.
Redis and Memcached
- Key - value pair in memory
- Cache and geo spatial index. etc.
No comments:
Post a Comment