Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Many teams submit jobs to a shared processing platform with priorities, and each worker instance keeps a local PriorityBlockingQueue. Low-priority tenants complain their jobs never run during busy periods. Design a fairer approach.

Strict priority ordering starves low-priority work whenever high-priority work keeps arriving, and per-instance PriorityBlockingQueues add two more problems: there is no global order, and queued jobs are lost when an instance crashes. A fairer design keeps jobs in a durable shared queue, splits them into per-tenant or per-priority queues served by weighted scheduling or with aging, enforces per-tenant quotas, and publishes waiting time per tenant and priority so fairness can be measured.

Why this question is asked

Shared platforms always face this complaint. Priorities seemed simple when there were three teams; with thirty tenants and a busy month, some tenants' jobs wait for hours or never run. The engineers did nothing wrong in their code, the scheduling policy simply never promised low-priority work any capacity. Interviewers ask senior engineers this to see whether they can name starvation, choose a fairness mechanism with known costs, fix the architecture underneath, and make fairness measurable. In this answer, we will see why strict priority starves, why local queues make it worse, compare weighted scheduling and aging, add quotas, design the durable queue, and decide what to measure.

1Why Strict Priority Starves Low-Priority Work

A PriorityBlockingQueue always hands a worker the highest-priority job available. That is the whole policy. If high-priority jobs arrive at a rate at or above what the workers can process, there is always a high-priority job available, so a low-priority job is never chosen. This is called starvation: work that is accepted but never served.

Consider numbers. The platform has 40 workers that together complete 400 jobs per minute. On a normal day, high-priority jobs arrive at 250 per minute, so 150 slots per minute are left for everything else. During month-end, high-priority traffic rises to 420 per minute. Now high-priority work alone exceeds capacity, its own queue grows, and low-priority jobs get zero slots for as long as the peak lasts. Nothing in the system says this is happening; the low-priority tenants simply notice their jobs are still waiting.

2Why Per-Instance Queues Make It Worse

Each worker instance has its own local PriorityBlockingQueue, filled by whatever load balancer or dispatcher sends it jobs. Priority is then only enforced within each instance. Instance A might be busy with low-priority jobs while instance B has a backlog of urgent ones, and neither knows about the other. So the platform is unfair in both directions: urgent jobs wait behind unimportant ones elsewhere, and low-priority jobs starve on busy instances.

The local queues also live only in memory. When an instance crashes, is redeployed or is scaled down, every queued job on it disappears unless the submitter notices and resubmits. In practice, some of the jobs that were said to never run may simply have been lost.

Step throughFrom local queues to a fair shared scheduler
  1. Submitterstenants submit jobs with a priority
  2. Admission controlper-tenant quotas, reject or defer beyond limits
  3. Durable queue storejobs table or broker, one logical queue per tenant and priority
  4. Fair dispatcherweighted selection across queues, aging for old jobs
  5. Workersclaim jobs, run them, acknowledge; crashed claims are retried

5 layers, from the top down. Step through them one at a time.

3Weighted Scheduling or Aging?

The first fairness tool is weighted scheduling. We keep a separate queue per priority level, or per tenant, or both, and the dispatcher picks among non-empty queues in proportion to weights. With weights 6, 3 and 1 for high, normal and low, out of every 10 jobs dispatched while all queues have work, 6 come from high, 3 from normal and 1 from low. Low priority is now guaranteed at least 10 percent of capacity, 40 jobs per minute in our example, even at peak. When a queue is empty, its share goes to the others, so no capacity is wasted. Algorithms such as weighted round robin or deficit round robin implement this, and the same idea applied across tenants gives each tenant a fair share.

The second tool is aging. A job's effective priority rises the longer it waits, for example by one level for every 10 minutes, capped at the top level. A low-priority job that has waited 30 minutes competes as high priority. Aging keeps a single ordering, which is simple, and guarantees an upper bound on waiting, but it gives less predictable shares, and under a long peak many aged jobs can crowd out genuinely urgent ones.

I would choose weighted scheduling across tenants and priorities as the main mechanism, because shares are predictable and easy to explain, and add a mild aging bonus within each queue so that nothing waits without bound. Whatever we choose, we should state the promise in plain words, such as low priority gets at least 10 percent of capacity and no job waits more than an hour while the platform is healthy.

Fairness mechanisms compared
MechanismGuaranteeCost
Strict priorityurgent first, alwaysstarves low priority under load
Weighted queues 6:3:1each level gets a minimum sharemore queues; weights to tune
Agingbounded waiting timeshares less predictable at peak
Per-tenant quotasno tenant fills the systembusy tenants are throttled

4Quotas Stop One Tenant Filling the System

Fair dispatching decides what runs next, but a single tenant can still flood the queue with millions of jobs, filling storage and making every queue scan slower. So admission control enforces per-tenant limits: a maximum number of queued jobs, a maximum number running at once, and possibly a submission rate. When a tenant exceeds its queue limit, new submissions are rejected with a clear error or deferred, rather than silently accepted.

Limits must be agreed with tenants and adjustable, because a fair limit for a small team is not fair for the payroll system at month-end. Reserving a guaranteed share for critical tenants and letting others share the rest is a common compromise.

5A Durable Shared Queue Instead of Local Ones

To get a global order and survive crashes, the queue must be shared and durable. A common, simple design is a jobs table in the database with columns for tenant, priority, status, enqueued_at and claimed_until. Workers claim jobs with a query such as SELECT ... FOR UPDATE SKIP LOCKED, which lets many workers take different rows without blocking each other, and they mark a job done when finished. A job whose claim expires because its worker died becomes claimable again, so nothing is lost; that means jobs can run more than once, and handlers must be idempotent.

At higher volume, a message broker can play the same role, for example with separate queues or topics per priority class and consumers that read from them according to weights. Either way, the in-memory PriorityBlockingQueue disappears, or remains only as a tiny local buffer of jobs already claimed.

6Making Fairness Measurable

Fairness is a promise, so we measure it. For every job we record when it was enqueued and when it started, and publish waiting time as percentiles, broken down by tenant and by priority: for example p50 and p99 wait for low priority in the last hour. We also publish queue depth per tenant and priority, jobs rejected by quotas, and the share of capacity each priority actually received.

Dashboards and alerts then answer the original complaint with data. If low-priority p99 wait exceeds the promised hour, we alert before tenants notice, and when a tenant complains, we can show what they received. These numbers also guide tuning: if low priority constantly hits its minimum share, the platform needs more capacity, not different weights.

7Follow-up questions

Would giving low-priority tenants their own workers solve it?

It removes starvation, but wastes capacity: dedicated workers sit idle when their queue is empty, while urgent work waits elsewhere. Weighted sharing gives each class a minimum share and lets idle capacity flow to whoever has work, which uses the same hardware better.

How does aging interact with quotas?

Quotas limit how much a tenant can have queued or running; aging changes the order among jobs that were admitted. They work together: quotas keep the queue bounded, and aging makes sure every admitted job eventually runs.

What happens to jobs already in local queues during the migration?

Run both paths for a while: new submissions go to the durable queue, while instances drain their local queues and stop accepting new local work. Once local queues are empty everywhere, the old path is removed. Draining on graceful shutdown also prevents losing jobs in the meantime.

8Conclusion

In this answer, we saw that strict priority ordering starves low-priority work whenever high-priority demand reaches capacity, and that per-instance in-memory queues add unfairness across instances and lose jobs on crashes. We replaced them with a durable shared queue, per-tenant and per-priority queues served by weighted scheduling with mild aging, per-tenant quotas at admission, and metrics for waiting time, depth and rejections per tenant and priority, so the fairness promise is explicit and measurable.

What to say in the interviewAbout 90 seconds aloud

Open with

The root cause is that strict priority is not a fairness policy. A PriorityBlockingQueue always serves the highest priority available, so whenever high-priority work arrives as fast as we can process it, low-priority jobs get no capacity at all, which is starvation.

Then, if they want more

Local queues per instance make it worse: there is no global order, so urgent jobs can wait behind unimportant ones on another instance, and everything queued in memory is lost when an instance crashes or redeploys.

I would move to a durable shared queue, for example a jobs table claimed with SELECT FOR UPDATE SKIP LOCKED, or a broker, with idempotent handlers because a crashed claim gets retried.

On top of that, the dispatcher keeps separate logical queues per priority and tenant and picks among them with weights, say 6, 3 and 1, so low priority is guaranteed about ten percent of capacity at peak and unused shares flow to others. I would add mild aging within queues so nothing waits without bound.

At admission I would enforce per-tenant quotas on queued and running jobs, so one tenant cannot flood the platform.

Finally, fairness has to be measurable, so I would publish waiting time percentiles and queue depth per tenant and priority, plus rejections, alert when low priority waits longer than what we promised, and use those numbers to decide whether we need different weights or simply more capacity.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Many teams submit jobs to a shared processing platform with priorities, and each worker...": https://scrivio-interview-library.netlify.app/java/queues-and-deques/ba77ff89b0/