Beanstalkd is the simplest broker in this catalog — a single-binary, single-process work queue with a tiny protocol, file-backed persistence (binlog), and a clean job lifecycle. It does not cluster, it does not federate, it does not have a management UI. What it does is take a job, hand it to one worker, and either get an ack (“delete”) or bury it for inspection. This article is the install we run for clients with a modest worker-pool need who do not want to operate RabbitMQ or Redis, and the operational shape an MSP wraps around it.
How to verify
Check the package, the binary, and what is on the standard port:
apt-cache policy beanstalkd
which beanstalkd
beanstalkd -v
ss -ltnp | grep ':11300\b' || echo "11300 free"
The beanstalkd port is 11300 — single port, single protocol, no TLS in the upstream daemon (TLS-terminating proxy if you need it across a network).
What’s happening
Beanstalkd has two concepts: tubes (named queues) and jobs (opaque byte payloads with a priority, delay, and TTR). A producer connects, picks a tube (use), and puts a job. A worker connects, picks one or more tubes (watch), and reserves a job. The reserved job belongs exclusively to that worker until the worker decides what to do with it.
The job lifecycle is:
- ready — in the tube, waiting for a worker.
- reserved — taken by a worker. The worker has
ttr(time-to-run) seconds to act before the job auto-returns to ready. - delayed — scheduled to become ready later (
putwith a delay). - buried — the worker called
bury(typically after a failure). The job is out of rotation; an operator mustkickit back to ready. - deleted — gone.
That is the whole state machine. No exchanges, no routing keys, no consumer groups, no offsets. The minimalism is the point.
Persistence is opt-in via the binlog (-b /var/lib/beanstalkd -f 0). Without the binlog, beanstalkd is purely in-memory; a restart loses every ready and delayed job. With the binlog, every state change is written to a sequence of journal files; on restart, the daemon replays them to rebuild state. The journal is append-only and segments are rotated based on the configured size.
Priorities are 32-bit integers, lowest wins. A priority-0 job preempts everything. Use priority sparingly — overusing it turns the queue into a sort tree and burns CPU.
No native fanout. One job goes to exactly one worker. If you need to fan a single produce out to N consumers, beanstalkd is not the right tool — use Redis pub/sub, NATS, or RabbitMQ topic exchanges.
The procedure
-
Install from the Ubuntu archive:
sudo apt update sudo apt install -y beanstalkd beanstalkd -v systemctl status beanstalkd --no-pager -
Configure persistence. Edit
/etc/default/beanstalkd:BEANSTALKD_LISTEN_ADDR=127.0.0.1 BEANSTALKD_LISTEN_PORT=11300 START=yes DAEMON_OPTS="-l 127.0.0.1 -p 11300 -b /var/lib/beanstalkd -f 0 -s 10485760"-bsets the binlog directory,-f 0flushes after every job (durable but slower), and-s 10485760rotates segments at 10 MiB. For lower durability and higher throughput, raise-fto a fsync interval in milliseconds. -
Set up the data directory:
sudo mkdir -p /var/lib/beanstalkd sudo chown beanstalkd:beanstalkd /var/lib/beanstalkd sudo systemctl restart beanstalkd sudo systemctl status beanstalkd --no-pager -
Smoke-test with the CLI (
apt install -y beanstalk-clior use a language client). With Python andpystalk/greenstalk:import greenstalk with greenstalk.Client(('127.0.0.1', 11300), use='emails', watch=['emails']) as c: c.put(b'send-welcome user@example.com', priority=100, ttr=60) job = c.reserve(timeout=5) print(job.id, job.body) c.delete(job) -
Inspect tubes and stats via the protocol —
stats-tubeandstatsare the operator commands. From the shell, withnc:printf 'list-tubes\r\nquit\r\n' | nc 127.0.0.1 11300 printf 'stats-tube emails\r\nquit\r\n' | nc 127.0.0.1 11300 printf 'stats\r\nquit\r\n' | nc 127.0.0.1 11300Look for
current-jobs-ready,current-jobs-reserved,current-jobs-buried, and per-tube counts. Thecmd-*counters tell you operation rates. -
Run workers under systemd. A worker is your application code reserving jobs in a loop; supervise it with a separate unit (
worker@.servicetemplate) so each worker process has its own restart policy. SetRestart=on-failureand an appropriateRestartSec. -
Set up a bury-and-alert pattern. When a job fails N times,
buryit instead of deleting; the buried count is a metric you alert on:try: process(job) c.delete(job) except RetriableError: c.release(job, delay=60) except FatalError: c.bury(job)A non-zero buried count is the signal that a poison message is sitting in the queue.
-
Lock the firewall. Beanstalkd has no auth — anyone reaching 11300 can
putandreservejobs. Bind to localhost or to the worker VLAN, never to a public interface:sudo ufw allow from 10.10.0.0/24 to any port 11300 proto tcp sudo ufw deny 11300 sudo ufw reload
Operational notes
- The binlog format is upstream-compatible across point releases but is not stable across major-version upgrades; back it up if it matters and confirm replay works on a staging instance after an upgrade.
- TTR (time-to-run) defaults are short — 60s is plenty for an email send, dramatically too short for a video transcode. Set it per job to the worst-case processing time.
releasereturns a job to ready (re-queues it);buryparks it out of rotation. Confusing the two is the most common worker-code bug.- No clustering, no replication. For HA, run two beanstalkd instances and have producers write to both (deduplicate at the worker), or accept that beanstalkd is a single-instance dependency and design around it.
- The protocol is line-based and easy to debug with
nc; this is a feature for a 2 AM incident.
Stack Harbor stands up beanstalkd as a deliberate choice for clients with modest worker-pool needs and a strong preference for operational simplicity — single-binary install, binlog sized to the job mix, workers under systemd, and a buried-job alert that catches poison jobs before they pile up. If your worker queue grew from a script on a developer laptop into a load-bearing piece of plumbing, this is the work covered by our Managed Operations practice.