TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Building a fair multi-tenant queuing system

176 pointsby tonyhbover 1 year ago

17 comments

siliconc0wover 1 year ago
I think you want controls around:<p>0) Load - I&#x27;m too loaded right now, I&#x27;m not processing your message. Maybe another worker will. This might be enqueued back into the low latency queue.<p>1) Role Limit - You&#x27;ve sent too many messages in too short of a time, I&#x27;m dequeueing this into the high latency queue.<p>2) Cost Limit - You&#x27;ve sent too many <i>expensive</i> messages, I&#x27;m dequeing this into the high latency queue.<p>3). Deadletter- Your messages are failing to be processed. We&#x27;re going to dequeue into deadletter and maybe we&#x27;re going stop processing them for for now.<p>So you have the normal low latency queue, the high latency backlog queue, and the deadletter queue. Ideally you have SLOs around end to end queue times and monitoring&#x2F;alerting to let you and your senders know their expectations may be not being met (i.e 99% of messages are processed within n MS).
评论 #39097132 未加载
Nilithusover 1 year ago
I found Amazon&#x27;s Builders Library to have a very insightful list of how to handle building multi tenant queue systems <a href="https:&#x2F;&#x2F;aws.amazon.com&#x2F;builders-library&#x2F;avoiding-insurmountable-queue-backlogs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;aws.amazon.com&#x2F;builders-library&#x2F;avoiding-insurmounta...</a><p>I think one of the big tools is Shuffle Sharding. The article talks about standard sharding by itself as not being enough to provide robustness in multitenant queues. But Shuffle Sharding I.E. assigning users to virtual groups of underlying queues and enqueueing to the queue with the smallest size gets you pretty far. It can limit throughput for individual users but implementing some simple work stealing logic on the consumer helps make sure you keep your throughput up.
评论 #39099943 未加载
评论 #39095924 未加载
fabian2kover 1 year ago
There are plenty of articles about writing simple job queues in Postgres using SKIP LOCKED, and I personally like that version quite a bit for cases where you don&#x27;t want to add another separate component just for the queue. But I haven&#x27;t seen anyone addressing fairness in such a queue, e.g. for the multi-tenant case.<p>Is there a simple way to get a very rough kind of fairness between tenants in this case? Doesn&#x27;t have to be actually fair, just fair enough that no tenant gets fully stuck behind a large block of jobs from another tenant.<p>The idea behind SKIP LOCKED is that you just get the first free job (potentially ordered by e.g. a priority column). Doing that in a way that switches between tenants doesn&#x27;t seem straightforward. You could execute the query once per tenant, but that would be rather inefficient for many tenants. Is there a reasonably straightforward way to achieve this?
评论 #39099703 未加载
评论 #39095673 未加载
评论 #39093583 未加载
评论 #39094519 未加载
评论 #39094416 未加载
评论 #39093767 未加载
评论 #39095115 未加载
评论 #39096621 未加载
评论 #39093717 未加载
andrewstuartover 1 year ago
&gt;&gt; with Postgres and SKIP LOCKED always cropping up<p>Note that SKIP LOCKED is available in Microsoft SQL Server and MySQL and I believe possibly also in Oracle and IBM DB&#x2F;2.<p>To the article, I suspect there will be alot of detail challenged here.<p>There&#x27;s talk in here about &quot;creating queues&quot; to handle the fairness problem. I might be misunderstanding what the hard bit is, but with a database backed queue you don&#x27;t have to create a queue - queues are virtual depending on what messages are in there and what other information is available such as username or tag. if you want to be &quot;fair&quot; around username then round robin on that, or fair around some other bit of data then tag the message when it goes into the queue and when you are processing, round robin on that.<p>What is the hard bit here, what am I missing?
jawnsover 1 year ago
This problem can be extended to systems like project management, where your workers are not computers but people.<p>For instance: Suppose you have a team of six people, and you&#x27;re being asked to tackle two projects for two clients, each of equal value to the business. One project will take two weeks to complete; another will take four months to complete.<p>How do you determine a &quot;fair&quot; way to divide up those projects? Do you do one before the other? Do you divide up your team&#x27;s capacity equally and do them in parallel?<p>This is the same sort of queuing problem described in the post. So a solution to the computer queuing problem might have interesting implications for the broader problem.
ctvoover 1 year ago
Is &quot;step function&quot; a term of art I&#x27;m just ignorant of in computer science? AWS Step Functions, sure. How it&#x27;s used here? No idea.<p>&gt; It enables developers to write declarative step functions...<p>&gt; With thousands of customers running thousands of step functions containing parallel steps....<p>&gt; If you&#x27;re familiar with step functions, you probably already see what&#x27;s happening here...
评论 #39093735 未加载
评论 #39096613 未加载
评论 #39094355 未加载
jll29over 1 year ago
Fair queuing in multi-tenant scenarios is also what describes what is going on in some financial trading systems: these queuing mechanisms are often opened up to regulators to demonstrate the fairness.
ykhliover 1 year ago
Great job abstracting away so much complexity!<p>&gt; each step is a code-level transaction backed by its own job in the queue. If the step fails, it retries automatically. Any data returned from the step is automatically captured into the function run&#x27;s state and injected on each step call.<p>This is one thing I&#x27;ve seen so many companies spending tons of time implementing themselves, and happens _everywhere_ -- no code apps, finance software, hospitals, anything that deals with ordering system...the list goes on.<p>Glad I no longer need to write this from scratch!
mbreeseover 1 year ago
Another place to look for inspiration is the HPC world. Fairshare job queues have been active on multi tenant HPC clusters for decades. Each job typically has a priority value assigned to it based on the submission time, expected resources required, and how much of the cluster the account&#x2F;user has used recently. Priorities can be continuously updated until the job is released for processing.
ceritiumover 1 year ago
For a small side project, instead of queuing all the tasks or writing a custom fair multi-tenant queuing system, I added all the &quot;tasks&quot; to the db, then with a periodic job I query with SKIP LOCKED for pending tasks and enqueue them on my queue system (sidekiq, Goodjob, etc). I only enqueue them if there are less than some amount of jobs pending, it is hardcoded, but I could do it dynamically.<p>The query logic take into consideration the tenants so, a big tenant (or misbehaving) can&#x27;t block small ones.<p>The periodic job is executed every few second, but it&#x27;s also enqueued when added new tasks to the db (unless it&#x27;s already enqueued) or when the query logic detect that there is more jobs available, so the lag is minimal.<p>At the moment I am doing this with only one type of jobs, but I want to expand it to most of the jobs, and let the &quot;query logic&quot; balance the queues.
quantum_bitsover 1 year ago
This is cool but pretty light on the details. Judging by how it reads, they create queues for each function, then create queues of queues for workers. It sounds similar to the QuiCK paper from Apple: <a href="https:&#x2F;&#x2F;www.foundationdb.org&#x2F;files&#x2F;QuiCK.pdf" rel="nofollow">https:&#x2F;&#x2F;www.foundationdb.org&#x2F;files&#x2F;QuiCK.pdf</a>
hot_grilover 1 year ago
A &quot;nuclear option&quot; I&#x27;ve seen in the wild is Queue-It. Puts your entire flow behind a queue that&#x27;s user-visible, with a waiting list page. Then presumably your own site&#x27;s logic doesn&#x27;t do any queuing.
评论 #39093895 未加载
wilgertvelingaover 1 year ago
Sounds a lot like Azure Durable functions. Which we started using recently. Curious to know if inngest could also fit our use case.
osigurdsonover 1 year ago
NATS has multi tenancy built in.
brightballover 1 year ago
This honestly sounds like a job for the BEAM (Erlang&#x2F;Elixir).<p>The preemptive scheduler would cover almost every need mentioned in the article.
评论 #39097784 未加载
评论 #39095226 未加载
1oooqooqover 1 year ago
i thought RH had solved that. just write a systemd unit file with the cpu quotas. bam. done. &#x2F;s?
maerF0x0over 1 year ago
btw &quot;fair&quot; is an entirely subjective and unproductive way to describe a system. There&#x27;s simply properties and priorities. Many of us have learned fair to mean a great variance of things. From per capita equal load, to you get what you pay for, to anything goes just don&#x27;t hurt anyone. In families we might see this as each child gets the same number of cookies. In capitalism fair is what you negotiate and agree to. The point isn&#x27;t what is or isn&#x27;t fair, but that there is no universal &quot;fair&quot;.<p>Should a user be able to jump the queue? What if they&#x27;re your number one driver of revenue? Or they have a time-sensitive function w&#x2F; a deadline? Or if they&#x27;ve produced no load on the system in the past $TIME_UNIT. All of these are not fair, just properties to be designed into a product.
评论 #39096716 未加载
评论 #39094029 未加载