A seller imported 37,576 products and the screen said Waiting. It still said Waiting the next morning. No worker had ever seen the job, because Redis had refused to store it:
OOM command not allowed when used memory > 'maxmemory'
Our queue Redis has 1 GB. 813 MB of it was a single list: half a million jobs waiting to update a different seller's customers.
Half a million copies of 13,664 customers
That seller keeps their books in BUSY, and our desktop connector auto-syncs their customer list: 13,664 customers. The queue worker applies one in about 0.25 s, so a full sync takes about an hour.
The connector was sending all 13,664 every 31 minutes. That's 27,000 jobs an hour in and 14,000 an hour out. The backlog had been growing for days and stood at 497,225 jobs, almost all of them for customers that hadn't changed.
That shouldn't be possible. Auto sync has a guard: before it dispatches, it looks for an open run for the store and waits if it finds one. An hour-long run should block the next one twice over.
The run history said every run had finished in about six minutes.
Who counted the work
A sync goes through two hops. A shared router job takes the customers and hands each one to the store's own queue, so one big seller can't starve everyone else. The store's worker then does the actual write.
Every job runs inside a wrapper that bumps the run's "processed" counter when the job returns. The router's job returned as soon as it had handed off its customers. So the wrapper counted 13,664 processed and the run flipped to COMPLETED before the real work had started.
connector → router job ── "done" ✓ (6 min) ← counter lives here
└→ store queue: 13,664 jobs, ~1 h of real work
The overlap guard asked an honest question and got a confident wrong answer. Each new sync saw a closed run, dispatched another 13,664 jobs, and stacked them behind the ones still waiting.
The import that started all this was a bystander. It queued all 37,576 rows as a single 3.7 MB job, and that one write tipped a nearly full Redis over.
Three fixes, in order of how much they matter
Count work where it happens. The wrapper now skips the router's job, so only the store worker's writes count. A run stays open until the last customer is actually applied, and the overlap guard works again.
Don't queue what's already queued. Each customer job gets a deterministic id built from the store, the customer and a hash of the payload. If the same customer with the same data is still waiting, the router skips it but still counts it, so the run can complete.
const jobId = `${storeId}-${syncId}-${md5(JSON.stringify(row))}`;
const existing = await queue.getJob(jobId);
if (existing && ['waiting', 'delayed', 'active'].includes(await existing.getState())) return skip(row);
Don't send what didn't change. After the worker applies a customer, it stores that payload's hash in a per-store Redis hash. The next sync compares hashes and drops the unchanged rows before queueing anything. The hash is written only after a successful write, so a customer that failed gets sent again. The key expires daily, which forces one full pass a day in case anything drifted. For this seller, a sync of 13,664 customers now queues only the handful that changed.
The cleanup was one script that drained that store's waiting list, taking Redis from 813 MB to 99 MB. It was safe because the next sync re-sends anything real. The import started a minute later.
What I'd reuse
- A progress counter is only as honest as where it sits. If a job's work is "hand this to someone else", it didn't do the work. Put the counter where the write happens.
- Anything that reads "done" inherits the lie. Here it was an overlap guard. It could as easily be a progress bar, a retry policy or an alert.
- Make re-sending the same thing free. A deterministic job id and a hash of the last applied payload turn a blind full sync into a diff, without the sender having to change.
- Watch the queue's input rate, not just its length. 27k in and 14k out is visible on day one. A full Redis shows up on day four, in someone else's import.