Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

work queues
web development

What is Beanstalkd?

Educative Answers Team


Beanstalkd can be defined as a work queue. It is used to manage workflow in web applications and increase speed.


  1. Jobs can be divided among multiple computers.
  2. Certain jobs can be given priority over others.
  3. Jobs that need to be done at specific intervals can be done as required.
  4. Disconnected clients can be allowed to return without losing their progress.


To initialize Beanstalkd, it needs to connect and listen on a port. This operation can be done using a command-line operation:

beanstalkd -l -p 20000

This command sets up Beanstalkd to listen at port 20000 on the host system. Next, Beanstalkd needs to be listening on this port in the program handling it as well:

import beanstalkc

# Connect beanstalk to thd correct ip address and port
beanstalk = beanstalkc.Connection(host = 'localhost', port = 20000)

This code snippet initializes a beanstalk client on localhost to listen on port 20000.

Jobs can be inserted into the queue using the put function:


As demonstrated in the example above, jobs need to be in string form to be inserted into the work queue.

To retrieve a job, the reserve function can be used:

job = beanstalk.reserve()

After processing, jobs need to be deleted. If they are not deleted, they are re-inserted into the queue after a certain amount of time.


A complete serverside function might look like:

import beanstalkc

beanstalk = beanstalkc.Connection(host='localhost', port=20000)

while True:
  job = beanstalk.reserve()
  #Job should be processed here or in another function

All code snippets, except the command-line script, were written in Python.


work queues
web development
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring