SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Cassandra at 46 Labs: Idempotent
Counters
July 17, 2014
Who is this guy?
I’m also the Founder, which in Latin means
“everyone else gets paid before me.”
~ Literal Translation
Founded in 2012
Currently handle around 1/2 Billion call billing records
per day.
What is 46 Labs?
We build realtime telecom analytics
and security solutions for Carriers and Enterprises
Shout Outs
#Cassandra IRC Channel
“Unbelievable resource”
!
“Thumbs up for the Startup Program”
Nate McCall
“Helped us in our time of need”
To all of you who aren’t in that ballpark…feel free to take
the pitch and swing away.
Patent Warning
So…we the have parts of this process related to the
handling of telecom analytics and billing records patented.
!
Fair Warning to the telecom folks in the room.
You can do an operation several times without changing
the result as a function of performing the operation.
Simple Answer:
What is idempotence?
Example:
For example, as “set” is idempotent. An “increment or decrement”
isn’t. Not just with Cassandra, but with anything, by definition.
But why?
Because counters are NOT atomic in Cassandra.
Why does it matter?
Because it is really, really, really hard to do anything
atomic and distributed, especially counters.
Since counters aren’t idempotent, by definition, and not
atomic in Cassandra, it means that if you repeated the
same counter operation 100 times….you might get
different results on each run.
So…
???
It means that you can’t use Cassandra counters for anything
requiring precision….like billing balances, voting, statistical
analysis or any time-series data that must be exact.
The higher the volume and the more nodes you have, the
more inaccurate the counters become.
And…?
If you are wanting atomic counters inside of a database
as of today’s date, then maybe.
Hint: We have tried both (and a lot more). They are slow. Like…really slow for this type of
operation and have hurdles way beyond just being slow.
So I should use Mysql or Couchbase?
Is there a chance that a better alternative exists that will
allow me to use Cassandra and have atomic and
idempotent counters?
So, All is Lost?
Yeap.!
!
But it involves some helpers.
+
How we do it
+
=
Our call billing records come off our infrastructure and go
into a RabbitMQ cluster.
!
Hint: you could use Kafka, Redis, 0MQ, etc.
The RabbitMQ queues are a nice and safe place for our messages to sit and
wait to be processed.
RabbitMQ
With RabbitMQ ACKs, we can be sure the messages are fully processed
before they are removed.
We wrote Java workers, who’s sole job in life is to:
1. Consume Messages from Rabbit!
!
2. Perform In-memory atomic increment operations (increment/decrement).!
!
3. Persist the message to Cassandra.!
!
4. Push a static counter value into Cassandra (i.e. a set instead of an increment) every X seconds.!
!
5. ACK that the operation is complete back to Rabbit.
Workers
(You can use whatever language you prefer)
1. You can stream analytics in realtime.
!
2. Being in-memory, it is ridiculously fast and lightweight.
!
3. Its atomic because each counter constituent is in a single thread.
!
4. Cassandra can be used to atomically persist the counter.
!
5. The counter data matches the underlying data used to generate it exactly.
Why is this special?
What happens if the worker crashes…its all in memory!!
!
Refer to step 4 in what our worker’s job is to do:
“Push a static counter value into Cassandra (i.e. a set instead of an increment) every second.”
Wait…
Since we push a static counter value into Cassandra, we now have an idempotent way
to recover gracefully in the event of a crash. The worker fires up, asks Cassandra what
it should have in its memory, then starts its atomic operations again. This backup
worker can come up (Zookeeper) on a different physical or virtual host if needed.
Since you are limited to a single thread processing a single counter….once you run out of memory
or saturate the CPU for that counter you can’t grow!!
!
Yeap. This is why we shard our data at the application layer and not the worker layer. We abstract
scalability further out knowing we have a finite amount of memory and processing power to play with at
the worker level.
You cant grow!
We can atomically handle 1M ops/sec from a single worker on a single moderately
powered server. If you are taxing that single server you need to re-think your
architecture.!
Sure it does.
Does it work?
We currently process over 2 million counter operations
per second using this method.
Questions?
If you think of any ones that you forgot to ask,
you can email me at trevor@46labs.com.

Weitere ähnliche Inhalte

Ähnlich wie Austin Cassandra Meetup re: Atomic Counters

Lessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterLessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterEugene Kirpichov
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous ApplicationsJohan Edstrom
 
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...Flink Forward
 
Work Queues
Work QueuesWork Queues
Work Queuesciconf
 
Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009pauldix
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with BlackfireMarko Mitranić
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey J On The Beach
 
Gearman and CodeIgniter
Gearman and CodeIgniterGearman and CodeIgniter
Gearman and CodeIgniterErik Giberti
 
OSDC 2017 | Something Openshift Kubernetes Containers by Kristian Köhntopp
OSDC 2017 | Something Openshift Kubernetes Containers by Kristian KöhntoppOSDC 2017 | Something Openshift Kubernetes Containers by Kristian Köhntopp
OSDC 2017 | Something Openshift Kubernetes Containers by Kristian KöhntoppNETWAYS
 
STP201 Efficiency at Scale - AWS re: Invent 2012
STP201 Efficiency at Scale - AWS re: Invent 2012STP201 Efficiency at Scale - AWS re: Invent 2012
STP201 Efficiency at Scale - AWS re: Invent 2012Amazon Web Services
 
Scylla Summit 2018: Meshify - A Case Study, or Petshop Seamonsters
Scylla Summit 2018: Meshify - A Case Study, or Petshop SeamonstersScylla Summit 2018: Meshify - A Case Study, or Petshop Seamonsters
Scylla Summit 2018: Meshify - A Case Study, or Petshop SeamonstersScyllaDB
 
Low latency in java 8 v5
Low latency in java 8 v5Low latency in java 8 v5
Low latency in java 8 v5Peter Lawrey
 
Case Study: Ansible and NASA
Case Study: Ansible and NASACase Study: Ansible and NASA
Case Study: Ansible and NASAAll Things Open
 
MongoDB and AWS Best Practices
MongoDB and AWS Best PracticesMongoDB and AWS Best Practices
MongoDB and AWS Best PracticesMongoDB
 
SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!Andraz Tori
 
Writing and testing high frequency trading engines in java
Writing and testing high frequency trading engines in javaWriting and testing high frequency trading engines in java
Writing and testing high frequency trading engines in javaPeter Lawrey
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++Mike Acton
 
Project Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a LaptopProject Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a LaptopDatabricks
 

Ähnlich wie Austin Cassandra Meetup re: Atomic Counters (20)

Lessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterLessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core cluster
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...
 
Work Queues
Work QueuesWork Queues
Work Queues
 
Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009Synchronous Reads Asynchronous Writes RubyConf 2009
Synchronous Reads Asynchronous Writes RubyConf 2009
 
2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire2019 StartIT - Boosting your performance with Blackfire
2019 StartIT - Boosting your performance with Blackfire
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey
 
Gearman and CodeIgniter
Gearman and CodeIgniterGearman and CodeIgniter
Gearman and CodeIgniter
 
OSDC 2017 | Something Openshift Kubernetes Containers by Kristian Köhntopp
OSDC 2017 | Something Openshift Kubernetes Containers by Kristian KöhntoppOSDC 2017 | Something Openshift Kubernetes Containers by Kristian Köhntopp
OSDC 2017 | Something Openshift Kubernetes Containers by Kristian Köhntopp
 
STP201 Efficiency at Scale - AWS re: Invent 2012
STP201 Efficiency at Scale - AWS re: Invent 2012STP201 Efficiency at Scale - AWS re: Invent 2012
STP201 Efficiency at Scale - AWS re: Invent 2012
 
Scylla Summit 2018: Meshify - A Case Study, or Petshop Seamonsters
Scylla Summit 2018: Meshify - A Case Study, or Petshop SeamonstersScylla Summit 2018: Meshify - A Case Study, or Petshop Seamonsters
Scylla Summit 2018: Meshify - A Case Study, or Petshop Seamonsters
 
Low latency in java 8 v5
Low latency in java 8 v5Low latency in java 8 v5
Low latency in java 8 v5
 
Case Study: Ansible and NASA
Case Study: Ansible and NASACase Study: Ansible and NASA
Case Study: Ansible and NASA
 
The cassandra odyssey
The cassandra odysseyThe cassandra odyssey
The cassandra odyssey
 
MongoDB and AWS Best Practices
MongoDB and AWS Best PracticesMongoDB and AWS Best Practices
MongoDB and AWS Best Practices
 
SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!SQL or NoSQL, that is the question!
SQL or NoSQL, that is the question!
 
Software + Babies
Software + BabiesSoftware + Babies
Software + Babies
 
Writing and testing high frequency trading engines in java
Writing and testing high frequency trading engines in javaWriting and testing high frequency trading engines in java
Writing and testing high frequency trading engines in java
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
 
Project Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a LaptopProject Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
Project Tungsten Phase II: Joining a Billion Rows per Second on a Laptop
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 

Kürzlich hochgeladen (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Austin Cassandra Meetup re: Atomic Counters

  • 1. Cassandra at 46 Labs: Idempotent Counters July 17, 2014
  • 2. Who is this guy? I’m also the Founder, which in Latin means “everyone else gets paid before me.” ~ Literal Translation
  • 3. Founded in 2012 Currently handle around 1/2 Billion call billing records per day. What is 46 Labs? We build realtime telecom analytics and security solutions for Carriers and Enterprises
  • 4. Shout Outs #Cassandra IRC Channel “Unbelievable resource” ! “Thumbs up for the Startup Program” Nate McCall “Helped us in our time of need”
  • 5. To all of you who aren’t in that ballpark…feel free to take the pitch and swing away. Patent Warning So…we the have parts of this process related to the handling of telecom analytics and billing records patented. ! Fair Warning to the telecom folks in the room.
  • 6. You can do an operation several times without changing the result as a function of performing the operation. Simple Answer: What is idempotence? Example: For example, as “set” is idempotent. An “increment or decrement” isn’t. Not just with Cassandra, but with anything, by definition.
  • 7. But why? Because counters are NOT atomic in Cassandra. Why does it matter? Because it is really, really, really hard to do anything atomic and distributed, especially counters.
  • 8. Since counters aren’t idempotent, by definition, and not atomic in Cassandra, it means that if you repeated the same counter operation 100 times….you might get different results on each run. So… ???
  • 9. It means that you can’t use Cassandra counters for anything requiring precision….like billing balances, voting, statistical analysis or any time-series data that must be exact. The higher the volume and the more nodes you have, the more inaccurate the counters become. And…?
  • 10. If you are wanting atomic counters inside of a database as of today’s date, then maybe. Hint: We have tried both (and a lot more). They are slow. Like…really slow for this type of operation and have hurdles way beyond just being slow. So I should use Mysql or Couchbase?
  • 11. Is there a chance that a better alternative exists that will allow me to use Cassandra and have atomic and idempotent counters? So, All is Lost? Yeap.! ! But it involves some helpers.
  • 12. + How we do it + =
  • 13. Our call billing records come off our infrastructure and go into a RabbitMQ cluster. ! Hint: you could use Kafka, Redis, 0MQ, etc. The RabbitMQ queues are a nice and safe place for our messages to sit and wait to be processed. RabbitMQ With RabbitMQ ACKs, we can be sure the messages are fully processed before they are removed.
  • 14. We wrote Java workers, who’s sole job in life is to: 1. Consume Messages from Rabbit! ! 2. Perform In-memory atomic increment operations (increment/decrement).! ! 3. Persist the message to Cassandra.! ! 4. Push a static counter value into Cassandra (i.e. a set instead of an increment) every X seconds.! ! 5. ACK that the operation is complete back to Rabbit. Workers (You can use whatever language you prefer)
  • 15. 1. You can stream analytics in realtime. ! 2. Being in-memory, it is ridiculously fast and lightweight. ! 3. Its atomic because each counter constituent is in a single thread. ! 4. Cassandra can be used to atomically persist the counter. ! 5. The counter data matches the underlying data used to generate it exactly. Why is this special?
  • 16. What happens if the worker crashes…its all in memory!! ! Refer to step 4 in what our worker’s job is to do: “Push a static counter value into Cassandra (i.e. a set instead of an increment) every second.” Wait… Since we push a static counter value into Cassandra, we now have an idempotent way to recover gracefully in the event of a crash. The worker fires up, asks Cassandra what it should have in its memory, then starts its atomic operations again. This backup worker can come up (Zookeeper) on a different physical or virtual host if needed.
  • 17. Since you are limited to a single thread processing a single counter….once you run out of memory or saturate the CPU for that counter you can’t grow!! ! Yeap. This is why we shard our data at the application layer and not the worker layer. We abstract scalability further out knowing we have a finite amount of memory and processing power to play with at the worker level. You cant grow! We can atomically handle 1M ops/sec from a single worker on a single moderately powered server. If you are taxing that single server you need to re-think your architecture.!
  • 18. Sure it does. Does it work? We currently process over 2 million counter operations per second using this method.
  • 19. Questions? If you think of any ones that you forgot to ask, you can email me at trevor@46labs.com.