Data Model
In memory data can be accessed using pointers/references.
Over the wire /from file data encoding/decoding has to happen.
Text - JSON, XML, CSV ( http)
Binary - Thrift, ProtoBuf, Avro
Schema Evolution
Avro - Backward/Forward
Why Replication ?
Replication Algorithms:
Leader based: ( Master-slave or Active-Passive replication)
Single-leader
Multi leader
Leaderless replicationLeader based replication
Leader -> followers
Replication lag
Append only Log structured format
SS tables
LSM
Update format
B+ tree
Partition Types
Partition by Key -value
Partition by Key Range
Partition by Hash
Skewed or hot spot ?
When data is not partitioned uniformly, single partition
can have more data that other partitions (Skewed). Because of it single partition will receive high load (hot spot).
Disadvantages of Hashed Parition
It naturally supports primary key. But if multiple/columns are to be searched (secondary indexes) , then it might be difficult..
Secondary Indexes - local store (document)
Store secondary index pertaining to that partition also in same partition. (local indexes)
Disadvantages:
Since each partition can have secondary index value, All partitions have to be queried to construct end result.
Scatter/gather approach - send requests to all paritions and merge the results.
there could be tail latency problems with scatter gather.
Secondary index - term (global)
store secondary indexes in global storage. But partition the global storage also by secondary index key.
for example : if color of the car is secondary key… partition by starting letter of the color or alphabetically…
Advantages : read efficient.. no scatte gather..
disadvantages : slow write, as data might have to be written into different partitions ( primary can into 1 partition, secondary index might go into other partitions
Partition rebalancing
moving data to another node ( rebalance)
Rebalancing
-
Service discovery or request routing
3 different ways to achieve is
How to Handle partition changes in request routing ??
systems like Kafka , Hbase uses zk as metadata coordinator system
Service discovery frameworks
Consul
Eureka
Map reduce - batch processing
Mapreduce jobs Hdfs
Mapper - collects all the data local to the machine
Reducer - brings in all sorted keys together based on partition key
SS table
It is append only log structure
No random writes
Key , value will be maintained in the memory called memtable.
Once memtable reaches its size , flushed into disk sstable
Reads will be scanned in memory first , then disk . So always updated value will retrieved from memory
Ss table compaction
As updates are not happening , if same record has multiple updates over multiple ss tables , then compaction process will create a new sstable by discarding old values
Bloomfilters
To check whether given element in the set or not
LSM
Log structured merge trees
Distributed System Characteristics
Scalability
Horizontal Scalability:
Adding more nodes to the cluster to handle additional traffic.
MongoDB/Cassandra DB supports horizontal scaling.
Vertical Scalability:
Scale single machine by adding more CPU cores, Memory or Disk.
- This kind of scaling needs downtime and also high cost for single resource.
Reliability
Systems should continue to work even when 1 or few components/systems fail.
To make the system reliable, we can either replicate the data or system.
It will cost more to make the system reliable.