Laravel Queue, Beanstalkd vs Database, what are the differences?

Nicekiwi picture Nicekiwi · Jun 28, 2015 · Viewed 8.9k times · Source

Is there much difference between using Beanstalkd and a database driver for queues?

What would some pros and cons be? The database queue seems to easier to setup and run, what should I know about using it?

Theres no real explanations in the docs about it.

Answer

Arpit picture Arpit · Jun 28, 2015

Using a database as a queue can be simpler to setup and probably easier to test on a development machine. But running a database as a queue in production may not be a very good idea; especially in a high traffic scenario. Although a database may not be the right tool for queueing, let's look at the pros & cons of using it as such.

Pros:

  • Easier to setup
  • May reduce the number of moving parts in your application if you use the same database

Cons:

  • For lot's of reads and writes, there has to be some mechanism for locking rows and updating the indexes etc.
  • Polling workers would also lock up an index in order to do work on it and update the row with the final status of the job.
  • In such scenarios, the writes to the DB may be queued and would take longer to execute.

Messaging queues such as SQS, Beanstalkd, RabbitMQ etc. are built to handle these scenarios. Since they only care about a message being stored and processed, they don't have to worry about locking and transaction logging (which is required by a database). Adding a messaging queue to your system will help it scale much more easily. Also, it'll let the database breathe by allowing it to do actual transaction processing without worrying about messaging as well.