Simplifying Message Queues with... Pizza
Jeremiah Talamantes
Security @ Podium, Founder @ Compliiant.io, Founder @ Mitigated.io (Sold), Founder @ RedTeam Security (Sold), Author of Building Security Partner Programs, Social Engineer's Playbook and Physical Red Team Operations
My first real introduction to message queues "at scale" and the concept of system decoupling through asynchronous-ness processing was at Microsoft. I understood it to be a system design choice for many reasons, but I only caught on once a coworker explained it using a pizza place as an analogy.
If you're unsure about the concept, I'm going to attempt to recreate the analogy for you all, but with a little more sauce. ;)
Wish me luck...
Please visit and share Compliiant.io with coworkers and colleagues!
The Orderly Chaos of a Pizza Kitchen
When you enter the pizza place, you're met with a symphony of scents and sounds. You approach the counter, where a friendly cashier takes your order and payment. This order is then written onto a pizza box and placed on a designated counter, a visible cue for the pizza chefs. The chefs, each a maestro in their own right, pick up the boxes, assemble the pizzas with a flourish, and slide them into the roaring ovens. Once the crusts are perfectly crisped and the cheese bubbles, the pizzas are moved to the pickup area, and the customers' names are called out.
This process is a dance of asynchronous steps where the cashier, the chefs, and the customers operate independently. The cashier doesn't pause to see the pizza baked; the chefs don't wait for customers to collect their orders. This independent yet interconnected workflow is the crux of asynchronous processing, akin to a message queue in software terms.
Message Queues in Software
Digitally, a message queue plays a similar role to our pizza counter. It's a temporary postbox where messages from one service (the cashier) are stored until the receiving service (the pizza chef) is ready to process them. This system is crucial in managing tasks that are not immediate or can be handled at a different pace than they come in.
For instance, in cloud computing, Amazon Web Services (AWS) offers Amazon Simple Queue Service (SQS), while Microsoft Azure provides Azure Queue Storage. These services act as the middleman, similar to our pizza box counter, ensuring that messages are delivered and processed even when parts of the system are busy or temporarily down.
Scaling Up: The Flash Sale Frenzy
Imagine a flash sale on an e-commerce platform, akin to a Friday night rush at the pizza place. Customers flood in, each eager to grab the limited-time offer. The system must handle this surge without faltering, much like our pizza chefs must keep up with the influx of orders.
Here, message queues like AWS SQS and Azure Queue Storage become the saving grace. They allow the system to handle a massive number of orders by queuing them up and processing them in an orderly fashion. This ensures that the system doesn't crash under pressure and that each customer's order is processed in the order it was received.
Independent Scaling: The Modular Kitchen
Just as a pizza kitchen might have multiple chefs specializing in different tasks, modern software systems are built with microservices that handle specific functions. These microservices can be scaled independently, much like adding more chefs to the kitchen during peak hours.
AWS and Azure both facilitate this modular approach. With AWS, you might use AWS Lambda in conjunction with SQS to handle different tasks that can scale based on demand. Azure offers a similar capability with Azure Functions and Queue Storage, allowing each function to scale independently based on the number of messages in the queue.
Resilience and Recovery: The Backup Plan
In our pizza place, if a chef were to step away, the pizzas don't stop. Another chef can pick up where the last one left off, ensuring that every order is fulfilled. Similarly, message queues provide resilience in software systems. If a service fails, the messages remain in the queue, and another service can pick up the task, ensuring continuity and reliability.
AWS SQS and Azure Queue Storage both offer features that help with message recovery and dead-letter queues, which handle messages that can't be processed, ensuring that no order – or message – is ever truly lost.
The Efficiency of Asynchrony
The pizza place is a microcosm of efficiency, where each part of the process is optimized for speed and quality. Similarly, message queues in software architecture, like those provided by AWS and Azure, ensure that systems can handle high volumes of tasks without compromising performance or reliability.
Just as customers leave the pizza place with a satisfying meal, users of a system backed by a robust message queue service experience seamless interactions, even during the most demanding times. Whether it's the heat of the kitchen or the rush of a flash sale, the message queue is the hero that keeps the digital world spinning without a hitch.
For a quick video explanation see this YouTube vid
If you like this article, please share my site, Compliiant.io, with your coworkers and colleagues. Compliiant.io offers cybersecurity services as a subscription.