Saturday, 26 June 2021

Realtime/Inmemory db

PERFORMANCE

  • Read data from hard disk - 63MB/sec
  • Read from SSD(Solid state disk) - 457MB/sec
  • Read from RAM - 4671 MB/sec

examples

  • Key value pairs
    • Redis
    • memcache
  • sql db
    • sqlite

Features of Real time/RAM DB

  • Expensive as RAM is expensive
  • Volatile
  • high performance
  • AVL tree() for indexing

Caching Best practices

  • Validity of data
  • High hit rate
  • Cache miss
  • TTL
Caching features/estimations
  • Tera byte 
  • 50K to 1M QPS
  • ~1 ms latency
  • LRU(eviction)
  • 100% availability
  • scalable
Cache access patterns
  • Write through
    • Write happens both in cache & DB. Acknowledgement happens after write happens in both
  • Write around
    • Write happens in DB only. Cache will be updated in subsequent read request.
  • Write back
    • Write happens in Cache and acknowledment happens. Another service will sync with db asyncly
Distributed transactions
  • Two phase commit
    • Prepare
    • Commit 
    • Cons- latency due to multiple http calls to micro services
  • Three phase commit
    • Recovers incase coordinator/participant fails

  • Saga
Databases
  • Choice of database - factors
    • Structured vs non-structured
    • Query pattern
    • Scale
  • Caching DB
    • Redis
    • memcache
  • Image/Video DB
    • Blob storage
      • Amazon S3  with CDN
  •  Text based search
    • Text Search engine
      • Elastic Search 
      • Solr
  • Timeseries database
    • For metrics monitoring
      • Open TSDB
  • Structured DB
    • need ACID
      • rdbms 
        • orcl, mysql, sqlserver, postgres
  • Document DB/ NOSQL DB
    • Columnar DB
      • Cassandra(Apache)
      • HBase
        • persists data
        • designed to handle a large amount of data across the distributed community server
        • Good large amount of data with finite number of queries. 
  • Redis
  • Elastic(Facebook)
  • mysql
 Design Interview tips
  • High level design or low level design
  • What functional features to be addressed
  • What non-functional features to be addressed
    • #users
    • scale
    • thruput, data size
  • Start with basic building blocks
    • how they interact
    • Get into depth of 1 or 2 components
  • Is it going in right direction
  • where does business flow start

No comments:

Post a Comment