Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Scaling Twitter with Cassandra

35,140 views

Published on

Published in: Technology

Scaling Twitter with Cassandra

  1. Scaling Twitter with Cassandra Ryan King Storage Team
  2. bit.ly/chirpcassandra ryan@twitter.com @rk
  3. Legacy • vertically & horiztonally partitioned mysql • memcached (rows, indexes and fragments) • application managed
  4. Legacy Drawbacks • many single-points-of-failure • hardware-intensive • manpower-intensive • tight coupling
  5. Apache Cassandra • Apache top level project • originally developed at Facebook • Rackspace, Digg, SimpleGeo, Twitter, etc.
  6. Why Cassandra? • highly available • consistent, eventually • decentralized • fault tolerant • elastic • flexible schema • high write throughput
  7. What is Cassandra? • distributed database • Google's BigTable's data model • Amazon's Dynamo's infrastructure
  8. Cassandra Data Model • keyspaces • column families • columns • super columns
  9. Cassandra Infrastructure • partitioners • storage • querying
  10. Partitioners • order-preserving • random • custom
  11. Storage • commit log • memtables • sstables • compaction • bloom filters • indexes • key cache • row cache
  12. Querying • get • multiget • range • slice
  13. Consistency
  14. Consistency • N, R, W
  15. Consistency • N, R, W • N = number of replicas
  16. Consistency • N, R, W • N = number of replicas • R = read replicas
  17. Consistency • N, R, W • N = number of replicas • R = read replicas • W = write replicas
  18. Consistency • N, R, W • N = number of replicas • R = read replicas • W = write replicas • send request, wait for specified number
  19. Consistency • N, R, W • N = number of replicas • R = read replicas • W = write replicas • send request, wait for specified number • wait for others in background and perform read- repair
  20. Consistency Levels • ZERO • ONE • QUORUM • ALL
  21. Strong Consistency • If W + R > N, you will have consistency • W=1, R=N • W=N, R=1 • W=Q, R=Q where Q = N / 2 + 1
  22. Eventuality • Hinted Handoff • Read Repair • Proactive Repair (Merkle trees)
  23. Potential Consistency
  24. Potential Consistency • causes • write-through caching • master-slave replication failures
  25. Example
  26. Read Repair • send read to all replicas • if they differ, resolve conflicts and update (in background)
  27. Hinted Handoff • A wants to write to B • B is down • A tells C, "when B is back, send them this update"
  28. Proactive Repair • use Merkle trees to find inconsistencies • resolve conflicts • send repaired data • triggered manually
  29. Parallel Deployment
  30. How we’re moving? • parallel deployments • incremental traffic shifting
  31. Parallel Deployment 1. build new implementation 2. integrate it alongside existing 3. ...with switches for dynamically move/mirror traffic 4. turn up traffic 5. break something 6. Fix it 7. GOTO 4
  32. ?

×