Queues should be empty
source link: http://joshvoigts.com/articles/queues-should-be-empty/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Queues should be empty
I’ve been writing a pubsub listener for work recently and had this silly “shower thought”: the ideal queue should be empty. Why? If the queue is not empty, it means that whatever job is consuming from the queue is not keeping up with messages coming into it. Ok, then if queues are supposed to be empty, then what are they good for?
Spikey workloads
One use for a queue is handling “spikey” workloads or scenarios where there is a mismatch between the rate at which events are produced and the rate at which they can be consumed. For instance, if there’s a sudden surge in demand for a service or product, a queue can help absorb the influx of requests until the system can scale up to handle the increased load.
Safely persisting data
Another use for a queue is safely persisting data. In pubsub, for example, a message is left on the queue until it’s been processed or acknowledged (ACK’d). If the process fails, it will never have been ACK’d so it will stay safely on the queue until the job is restarted.
A job can also be failed purposefully with a negative acknowledgement (a NACK). You might do this if the job is not ready yet or if a service the job depends on has failed. After a NACK, the message will be returned to the queue to be processed at a later time. Usually using a backoff policy so that the consumer doesn’t continuously pull the same item.
Decoupling components
Queues can be used to decouple components in a distributed system. If one component produces events and another component consumes them, a queue can act as a buffer between the two components. This way, the producer doesn’t need to know anything about the consumer and vice versa. They simply interact with the queue, which handles the communication between them.
Enabling asynchronous processing
Another use for queues is to enable asynchronous and/or parallel processing. With a queue, you can submit a job or task to be executed later and avoid blocking the caller. If you have an application that generates PDFs, you could submit the task and ACK immediately allowing the job to finish in the background. It also makes it easy to parallelize jobs by having multiple consumers pull from the same queue.
Empty queues may be the best queues…
… but they’re still useful.
Recommend
-
69
Job Queues in Go At RapidLoop, we use Go for nearly everything,...
-
37
Please consider subscribing to LWN Subscriptions are the lifeblood of LWN.net. If you appreciate this content and would like to see more of it, your subscription will help to ensure that LWN...
-
46
Website monitoring without the hassle. Multi-location uptime monitoring, broken links detection & ssl certificate expiration reporting.
-
38
I recently did a corporate TLA+ workshop and some people asked what TLA+ specs look like in practice. If you looked at the most common public examples, you’d proba...
-
33
TOC Linux network queues overview Fitting the sysctl variables into the Linux network flow Ingress - they're coming Egress - they're leaving ...
-
25
Posted on May 14, 2019 Part 6 of a 6-part series on Breadth-First Traversals Tags:Haskell Fusio...
-
44
Imagine that you have a big log of financial transactions and you want to extract the largest 5 transactions that happened. We might have a few ways to approach this. 1. Sort them? Duh. If we have 3 milli...
-
28
Strategies for Working with Message Queues Caleb Doxsey Message queues like Apache Kafka are a common component of distributed systems. T...
-
38
README.md RQ (Redis Queue) is a simple Python library for queueing jobs and processing them in the background with workers. It is backed by...
-
17
Why are there so many concurrent queues implementations in Java? January 10, 2020 Category: The package java.util.concurrent.atom...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK