Live data from Hacker News

Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

blog.gomiso.com

11–20 of 29 posts

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#11
post #5

I think the article is good, however, I feel compelled to weigh in from the countervailing general direction: I am a message queue skeptic. Not that they should never be used, but rather a general feeling that complex, dedicated message queue software is often used for engineering problems between two or three orders of magnitudes too small before they deliver value. And, for most projects, queue replacement is not t…

Initially this might seem different from the topic at-hand, but bear with me please:

Several years ago (probably first or second year of high school) I wrote and distributed amongst my friends a small desktop game. The program e-mailed me their new high-scores and internal game diagnostics daily. I found that this was too often so I rewrote the game to send these data daily. This way of retrieving data sucked. Often, I would get empty or unimportant messages.

Eventually I had the realisation that time-oriented polling was the wrong philosophy. Instead, there should be a "this event has happened now" (e.g. 500kb of diag. generated) algorithm that calls the polling routine/invokes the 'stuff to be done traverser'. If I understand the problem correctly, the mass e-mail example, you could make a simple counter as part of the HTTP request. When this counter hits a certain you-determined threshold value (e.g. there are 500 jobs to do), then call the traverse/processing code:

if jobs_to_do > thresh then invoke some async processing

The takeaway from this post is that, in my opinion, time-based (cron job-bish) polling algorithms are inefficient but can be replaced with a rudimentary event-driven ones.

And just BTW, 'countervailing' - I'm deifying this word. Holy s*. I'm going to use it all the time.

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#12
An in-(or out of) process (async) driver (exposing an API supporting future semantics) can provide DB specific queueing to some extent. MQs and MOMs are very useful but not always necessary and the additional latency due to node hops is sometimes not acceptable.

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#13
post #5

I think the article is good, however, I feel compelled to weigh in from the countervailing general direction: I am a message queue skeptic. Not that they should never be used, but rather a general feeling that complex, dedicated message queue software is often used for engineering problems between two or three orders of magnitudes too small before they deliver value. And, for most projects, queue replacement is not t…

Interestingly, that's why Microsoft created SQL Server Service Broker. They had te infrastructure for reliable message queuing and transactional support, so they created SQL Server Service Broker!

Not sure I ever took off though...

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#14
disclaimer: co-author of NSQ [1] here

Agreed. Message queues play an important role for us (bitly) in being a layer of fault tolerance, buffering, and a means to perform various operational tasks.

They're so important to us that we decided to build something that worked exactly like we wanted.

NSQ is a realtime distributed message processing system where we've taken the approach of focussing on making it ops friendly and easy to get started.

IMO, solutions that make it easy to develop on and administrate are most important... because things break. NSQ is straightforward to deploy (limit dependencies), simple to configure (runtime discovery), and client libraries provide a lot of functionality important for handling failures (like backoff, deferred messages, etc.) for a variety of use cases.

We've written an in-depth introductory blog post [2] about NSQ that has more details.

[1]: https://github.com/bitly/nsq [2]: http://word.bitly.com/post/33232969144/nsq

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#15

With a traditional database this typically means a service that is constantly querying for new processing tasks or messages. Traditionally, but not necessarily; PostgreSQL supports the LISTEN and NOTIFY commands for asynchronous notifications, without polling.

Also, Axiom, my favorite little Python object layer over SQLite, has native scheduler support. Whenever loading a store (well, starting the store's scheduler service), all things-to-happen are scheduled to run using Twisted's event loop. And, well, event loops are very good at efficiently waiting for things to be done in the future :)

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#16
Look forward to reading the future articles. Right now I'm working on a side project that has a need for some asynchronous tasks. I was planning on using beanstalkd but the one thing that concerns me is that if the queue goes down the outstanding jobs are not persisted. Any recommendations on the best way around this?

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#17
1) The article claims that queues is a replacement for a database thus it solves all the problems with DB solution. In reality, if you have to have reliability and data integrity guarantees, then a messaging queue system will be using a DB under the hood (in the best case, it will be off-the-shelf DB, in the worst, something homegrown). All the same problems and considerations apply. You run into the same DB problems with the need to manually optimize queue tables, etc. because message queues rarely do a good job there. Of course, all the commit issues discussed above apply to.

2) The issue with polling is easily solved by using modern DBs (e.g. Postress with listen/notify) or just plain old triggers/stored procedures. Yes, it will be a custom solution but it will be simpler from operational perspective than a "generic" do-it-all solution.

3) Lastly, it all depends on the task. At WePay we use gearmand backed by a DB. We have seen it working really well and helping us handle 1000x spikes from normal load w/o a single problem. However, we did quite a few modifications to get there from the "stock" code to customize it to our use-case and have 200% data integrity and reliability guarantees.

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#18
post #17

1) The article claims that queues is a replacement for a database thus it solves all the problems with DB solution. In reality, if you have to have reliability and data integrity guarantees, then a messaging queue system will be using a DB under the hood (in the best case, it will be off-the-shelf DB, in the worst, something homegrown). All the same problems and considerations apply. You run into the same DB problems…

I understood the point as "Don't use a database as a replacement for a queue". Use the right tool for the job.

The fact that gearmand is backed by a DB is not at all the same as using a DB for a queue directly. Gearmand just uses a database as a backup that it can reload tasks when it get's restarted.

Re: Asynchronous Processing in Web Apps, Part 1: A Database Is Not a Queue

#19
post #18
post #17

1) The article claims that queues is a replacement for a database thus it solves all the problems with DB solution. In reality, if you have to have reliability and data integrity guarantees, then a messaging queue system will be using a DB under the hood (in the best case, it will be off-the-shelf DB, in the worst, something homegrown). All the same problems and considerations apply. You run into the same DB problems…

I understood the point as "Don't use a database as a replacement for a queue". Use the right tool for the job. The fact that gearmand is backed by a DB is not at all the same as using a DB for a queue directly. Gearmand just uses a database as a backup that it can reload tasks when it get's restarted.

Yes. However, you have same issues with DB tables receiving tons of inserts/deletes/selects. This is the worst possible DB load :)
Post reply on HN