performance · queue · testing · ecowell · database · deployment

Part 2: The Good Queue — zero errors at fifty users on half a CPU

2 December 2026 · 8 min read

Part 1 ended with EcoWell 40 times faster for ten busy users, but still falling over at fifty. This is how I got it to fifty users with zero errors on the same half-CPU, 512 MB server, using an idea I’ve started calling a “good queue”. All numbers were measured on our UAT system on 27–28 November 2026.

Where part 1 left off

After the first round of work, the backend no longer crashed, and ten people clicking fast got answers in about 0.15 seconds. But the step load test told the rest of the story:

Users Typical Slowest 5% Errors
10 0.15 s 2.1 s 0%
20 2.1 s 6.9 s 0% (stopped early)
30 1.9 s 7.2 s 0% (stopped early)
50 3.4 s 18 s 34%

“Stopped early” is a rule I built into the test: it stops itself once the slowest 5% of responses pass 5 seconds or errors pass 2%, so a test can never knock the server over. At 20 and 30 users it hit the 5-second rule.

Profiling had already shown why. The server’s CPU was mostly idle. The real limit was the database’s REST layer, which handles about 40 calls a second before calls start waiting in line. Every request beyond that queued.

A long line of worried requests waiting in front of an exhausted database

First principles: a queue doesn’t create capacity

My first instinct was “put a queue in front of the database”. Before building one, I had to be honest about what a queue can and can’t do.

If the database can serve 40 calls a second and we send it 60, a queue doesn’t fix anything. It grows without limit, and every request waits longer. That’s exactly what was happening at 50 users. Waiting time is just the line length divided by how fast the line moves (Little’s law), so if work arrives faster than it leaves, the wait explodes.

So a useful queue has to do two jobs at once:

  1. Protect the database. Never send it more than it can handle, so it stays in its fast zone and the server stays up.
  2. Shrink the demand. Combine work so that 60 “asks” turn into far fewer than 40 real database calls.

A queue that only does the first job just makes failure more polite. I wanted one that did both. I started calling that a good queue.

Requests lining up behind ropes, handed in one at a time through a single gate to the database

The design

Every database call now goes through one gateway in the backend:

  • A fixed number of calls in flight. The database gets at most a set number of concurrent calls, never a pile-up.
  • Priority lanes. A person waiting on a screen goes ahead of background work like polling and reports.
  • Deadlines. Each request carries a “give up after N seconds”. If it’s already too late before it starts, it’s dropped before it costs a database call.
  • Fail fast, never fall over. If the queue is full, the server answers immediately with “busy, retry shortly” instead of piling up until it runs out of memory.
  • Batching and sharing. Identical reads arriving at the same moment share one database call; lookups by id are combined.
  • Background jobs. Notifications, audit records, PDFs and messages move to a job queue in our own Postgres, with retries.
  • Pre-computed summaries for dashboard counts, and pushed updates instead of every screen polling.

Requests entering the QUEUE box and being carried along a conveyor belt to the database

Alongside it, I set a standard for errors, because many of the hundred bugs we’d just found were bad messages hiding the real cause: a missing ticket reported as “service unavailable”, bad input returning a 500, two hundred “Unable to…” messages that threw away the reason. Now every error carries a stable code, a plain message, what to do next, whether it’s safe to retry, and a request id that ties the screen to the server log. The portals read that and retry quietly when it’s safe, or show the specific message when it isn’t. A missing ticket now comes back as 404 TICKET_NOT_FOUND instead of a misleading 503.

Four panels: a crowded gate, priority lanes, shared reads, and "Busy, retry" for reads versus a locked document for writes

Round 1: stable, but not cheaper

The first version did the protective half well. In a local test at 50 users on the same limits, errors fell from 34% to about 5%, the slowest responses improved, and nothing crashed.

Requests hurrying toward the gate with boxes, held in order by ropes

But it didn’t reduce database calls. Batching only combined 4–8% of requests, and requests still averaged 2.5 to 4.5 database calls. The queue was managing the line, not shortening it.

Judgement: this is the trap I’d described to myself in first principles: a queue that only shapes load. Instead of tuning the queue harder, I went back to measuring where the calls came from.

A worker carrying queued requests through a processing step into the database

Round 2: find the hog, then share the answer

Counting database calls per request from the access logs gave the answer straight away:

Request Database calls per request
Master performance report about 27
Technician installations about 8
Installations list about 7
Customer profile about 5
Tickets about 5
Bookings about 4

The master report alone cost as much as five to seven normal screens, and the Admin dashboard ran it every time it opened.

The second insight was about sharing. Most of our users work in one branch, so twenty people asking for “today’s bookings in Test Branch” were asking the database the same question twenty times. Each user’s cache was private, so none of them helped the others.

So round 2:

  • A shared, permission-safe cache for branch-level reads. The cache key includes everything that decides who may see the data (branch, filters, scope), so sharing never leaks one person’s view to another. Any write to that data clears it.
  • 20-millisecond coalescing. Identical reads arriving within the same 20 ms share one database call.
  • A 90-second shared cache for the master report for branch managers.

Results, on half a CPU and 512 MB

Same script as part 1, same server size. Each simulated user opens a screen and its main list, pauses 2 to 6 seconds, and repeats.

Users Before (release 18) After (good queue)
10 0.15 s typical / 2.1 s slowest 5% / 0% errors 0.13 s / 0.96 s / 0%
20 2.1 s / 6.9 s / stopped early 0.19 s / 0.82 s / 0%
30 1.9 s / 7.2 s / stopped early 0.23 s / 1.0 s / 0%
50 3.4 s / 18 s / 34% errors 0.32 s / 2.5 s / 0% errors

At fifty users the server handled 3,250 requests in three minutes, about 18 a second, with zero failures, and the typical response stayed under a third of a second. The test never had to stop itself.

A celebrating worker beside an empty queue tray and a database with a green check

The deploy that failed, and why I was glad it did

One release in this stretch failed to deploy, and it’s worth telling because the system did exactly what it should.

One of the bug fixes protected /health/db, which had been an open endpoint running eight database queries for anyone who asked. The fix put it behind a login. But Render used /health/db as its health check. The new server answered Render with “401, please log in”, Render decided it was unhealthy, refused to switch traffic to it, and kept the old version running. Nobody noticed anything.

The fix was to point Render’s health check at /health, which is cheap and public, and keep the security fix. The near-miss was elsewhere: I had already updated the “expected release version” setting that the startup check compares against. If the old server had restarted before I put that setting back, it would have refused to start. Now I restore those settings automatically whenever a deploy fails.

The rule that comes before speed

While building this, I wrote down the one rule that beats every performance goal: business data is never lost. Bookings, payments records, invoices, installations, stock movements, tickets and audit records may be slow, but they may not disappear, be duplicated, or be silently overwritten.

A queue is exactly the kind of thing that can break that rule if it’s careless, so the design follows it:

  • Only reads are ever shed. “Busy, retry” applies to reads. A write that has started is never dropped or timed out.
  • Writes are never batched across users.
  • Writes are only retried automatically with an idempotency key, so a retry can’t create a second booking.
  • Background work is created in the same transaction as the data it belongs to, processed at least once, retried, and parked in a visible “failed” list rather than deleted.
  • Caches can be a few seconds old, but every write clears them, and writes check the record’s version so a stale screen can’t overwrite newer data.
  • Summary tables are copies, never the source of truth.

And when something does fail, the user is told clearly: saved (with the new booking or ticket number), failed (with the reason and their form intact), or “we couldn’t confirm, checking…” followed by a real answer. Never a spinner that runs forever.

A happy worker raising fists beside a completed tray, with a green check on the database

What I learned

  • A queue shapes load; it doesn’t create capacity. Pair it with something that removes work, or it only makes failure more polite.
  • Count the calls per request. One report making 27 database calls mattered more than every clever queue setting.
  • Share answers that are genuinely shared. Twenty people in one branch asking the same question should cost one database call, as long as the cache key respects who may see what.
  • Correctness first, then speed. Zero errors and zero data loss on a small server beat a faster system that sometimes drops a booking.
  • Let deploys fail safely. A health check that refuses a bad release is a feature, as long as rolling back leaves everything consistent.

The whole story at a glance

Five panels recapping the article: overload, the good queue, the design pieces, shared answers, and a calm, healthy database

AI use: Written with AI assistance from my own notes and project facts, then reviewed by me. Images are AI-generated. How I use AI

Loading reactions…

Working on something similar? Let's talk.

Same problem, a question about this article, a collaboration, or an open-source project you would like me to contribute to. Pick whichever door you like: