AI video API fair scheduling: Tenant Queues and Limits

Nov 11, 2026·9 min read

One customer submits a batch of 200 video jobs; another submits one preview a moment later. AI video API fair scheduling prevents that preview from waiting behind the entire batch simply because it arrived later. The scheduling policy belongs in your application's job system: accepting a request, deciding whose job starts next, and tracking an external generation are separate responsibilities.

For developers building with GenRelay, this is an application architecture pattern, not a claim about a built-in scheduling feature. Start with the GenRelay video API, then design dispatch around your own tenants, resource constraints, and accounting rules.

What is AI video API fair scheduling?

AI video API fair scheduling distributes opportunities to start generation jobs across tenants rather than letting one tenant's backlog dominate shared capacity. A tenant is the customer, organization, or workspace whose usage you isolate.

A scheduler selects eligible work when capacity becomes available. Concurrency means the number of jobs currently counted as active, not the number submitted per minute. A global concurrency cap bounds active jobs across the scheduling domain; a per-tenant cap bounds one tenant's share.

Fairness needs a stated unit. Equal turns provide roughly equal start opportunities among eligible tenants, not equal GPU time, dollars, or completion latency. Two tenants can receive alternating starts while one consumes substantially more processing time because its jobs run longer. Avoid promising equal response times from a policy that controls dispatch order.

Why can FIFO be unfair to smaller tenants?

First-in, first-out scheduling, or FIFO, favors arrival order without considering which tenant owns the backlog. That makes it predictable within one queue but vulnerable to a large batch occupying many successive dispatch opportunities.

Per-tenant queues preserve arrival order within each tenant while allowing the scheduler to alternate between tenants. Round robin means visiting eligible tenants in a rotating order and taking one job per turn. A tenant at its cap is skipped, not allowed to block everyone behind it.

Policy Selection rule Useful property Limitation
Global FIFO Oldest waiting job Simple arrival ordering Large batches dominate subsequent starts
Tenant round robin One job per eligible tenant turn Backlogs do not buy extra turns Starts are not equal resource usage
Weighted round robin Assign more turns to specified tenants Expresses explicit service allocations Weights need governance and monitoring
Cost-aware scheduling Charge estimated work against an allocation Can account for different job sizes Estimates can be inaccurate

Round robin is a reasonable starting point when tenant isolation matters more than exact cost allocation. Keep the policy explicit: idle tenants do not accumulate unlimited future turns, and caps are ceilings rather than reservations of idle capacity.

How do tenant and global caps work together?

A job can start when its tenant has waiting work, its tenant's active count is below its cap, and the total active count is below the global cap. All three conditions must hold at the moment the job is claimed.

For example, with a global cap of three and tenant caps of two, two busy tenants can collectively fill three slots. One tenant alone can fill two. Leaving the third slot idle is intentional under that policy; permitting temporary borrowing would require a different rule.

Do not silently treat every model as one interchangeable resource pool. Your production system may also need separate capacity limits by model or destination. Those limits constrain eligibility alongside tenant fairness; they do not replace it.

What does a runnable round robin example demonstrate?

The following standard-library Python program demonstrates capped dispatch and completion bookkeeping locally, without making network requests. Its integer jobs represent simulated work; completing a job explicitly releases its slot.

Save the code as fair_scheduler.py and run python3 fair_scheduler.py. The assertions exercise cap enforcement, a capped tenant being skipped, invalid completion, unique job identifiers, and queue rotation.

from collections import deque


class Scheduler:
    def __init__(self, global_cap, tenant_caps):
        caps = [global_cap, *tenant_caps.values()]
        if not tenant_caps or any(type(c) is not int or c < 1 for c in caps):
            raise ValueError("caps must be positive integers")
        self.global_cap = global_cap
        self.caps = dict(tenant_caps)
        self.queues = {t: deque() for t in self.caps}
        self.ring = deque(self.caps)
        self.active = {t: 0 for t in self.caps}
        self.running = {}
        self.seen = set()

    def submit(self, tenant, job):
        if tenant not in self.queues:
            raise ValueError("unknown tenant")
        if job in self.seen:
            raise ValueError("duplicate job")
        self.seen.add(job)
        self.queues[tenant].append(job)

    def dispatch(self):
        started = []
        while len(self.running) < self.global_cap:
            for _ in range(len(self.ring)):
                tenant = self.ring[0]
                self.ring.rotate(-1)
                if (self.queues[tenant]
                        and self.active[tenant] < self.caps[tenant]):
                    job = self.queues[tenant].popleft()
                    self.running[job] = tenant
                    self.active[tenant] += 1
                    started.append((tenant, job))
                    break
            else:
                break  # Every tenant is empty or capped.
        self.check()
        return started

    def complete(self, job):
        if job not in self.running:
            raise ValueError("job is not running")
        tenant = self.running.pop(job)
        self.active[tenant] -= 1
        self.check()

    def check(self):
        assert len(self.running) <= self.global_cap
        assert sum(self.active.values()) == len(self.running)
        for tenant, count in self.active.items():
            assert 0 <= count <= self.caps[tenant]
            assert count == sum(t == tenant for t in self.running.values())


def rejects(fn):
    try:
        fn()
    except ValueError:
        return
    raise AssertionError("expected ValueError")


if __name__ == "__main__":
    rejects(lambda: Scheduler(0, {"A": 1}))
    rejects(lambda: Scheduler(1, {"A": True}))
    s = Scheduler(3, {"A": 1, "B": 2})
    for job in range(4):
        s.submit("A", job)
    for job in range(10, 14):
        s.submit("B", job)
    assert s.dispatch() == [("A", 0), ("B", 10), ("B", 11)]
    assert s.dispatch() == []
    rejects(lambda: s.complete(99))
    rejects(lambda: s.submit("A", 0))
    s.complete(10)
    rejects(lambda: s.complete(10))
    assert s.dispatch() == [("B", 12)]  # A remains capped.
    s.complete(0)
    assert s.dispatch() == [("A", 1)]
    while s.running or any(s.queues.values()):
        for job in list(s.running):
            s.complete(job)
        s.dispatch()
    assert not any(s.active.values())

    r = Scheduler(1, {"A": 1, "B": 1, "C": 1})
    for tenant, base in [("A", 0), ("B", 10), ("C", 20)]:
        for offset in range(2):
            r.submit(tenant, base + offset)
    order = []
    for _ in range(6):
        [(tenant, job)] = r.dispatch()
        order.append(tenant)
        r.complete(job)
    assert order == ["A", "B", "C", "A", "B", "C"]
    print("PASS: caps, skip, completion, uniqueness, rotation")

The rotating cursor advances after each examined tenant, including a successful selection. A complete unsuccessful scan ends dispatch, preventing an infinite loop when queued jobs exist but every relevant tenant is capped. All tenants are configured upfront; dynamic registration is outside this demonstration.

Why is admission budgeting separate from scheduling?

Admission control decides whether to accept work; scheduling decides which accepted job may start next. A fair rotation cannot stop a customer from accumulating unaffordable commitments or an unbounded backlog.

Reserve an estimated budget when admitting work, then reconcile it against actual billable usage. Set queue-depth and request-size limits independently. When admission fails, return an explicit rejection rather than placing work in an invisible waiting state. See queue admission control for that boundary.

For budgeting examples dated November 10, 2026, the supplied rates are Grok 1.0 at $0.010 per second, Grok 1.5 at $0.022 per second, Omni Flash 720p at $0.10 per generation, and Omni Flash 1080p at $0.15 per generation.

An assumed aggregate of 1,000 billable seconds estimates $10 for Grok 1.0 or $22 for Grok 1.5. One hundred billable generations estimate $10 for Omni Flash 720p or $15 for Omni Flash 1080p. These are arithmetic estimates, not statements about supported clip durations. Omni Flash amounts are per generation, not per second. Price estimates help admission accounting; they do not establish how long jobs occupy concurrency slots.

What changes in a durable production scheduler?

A production scheduler must claim work and reserve capacity transactionally, with durable state that survives process crashes. The example is single-process, in-memory, and unsuitable for concurrent callers without additional coordination.

A transaction is an atomic group of state changes that commits together or not at all. Within the relevant transaction, verify eligibility, transition the selected job from queued to claimed, and reserve its tenant and global capacity. Competing workers must not both observe the same free slot and independently consume it. Lock shared capacity records in a consistent order, or use an equivalent atomic coordination design.

Do not hold a database transaction open during an external API request. Persist dispatch intent first, then record the external job identifier. A crash between submission and recording creates uncertainty; reconcile it using documented external behavior rather than assuming exactly-once submission.

A worker lease is a time-limited claim on processing responsibility. An expired lease does not prove that the external generation stopped. Keep capacity accounting tied to unresolved external work, and use worker leases and recovery to distinguish ownership recovery from starting another generation.

Make terminal transitions idempotent: repeated completion handling must not release a slot twice. Persist cancellation intent, retries, budget reservations, and reconciliation results. The demonstration retains every job identifier forever; production needs a documented retention policy and durable deduplication window.

How can you tell whether the policy is fair?

Measure per-tenant queue waiting time, dispatch share, active concurrency, and time spent blocked by each cap. Separate waiting time from generation runtime so a slow generation does not masquerade as a scheduling defect.

Test a large batch alongside intermittent small submissions. Also test long-running jobs, unavailable resource pools, duplicate completion events, and worker crashes. Compare behavior against the declared fairness unit, not an unstated promise of equal completion speed.

What questions do developers ask about fair scheduling?

The recurring questions concern preemption, tenant identity, retries, and where the scheduling policy belongs.

Does round robin interrupt an active video generation?

No. This policy chooses the next job to start; it does not interrupt work already running. New tenants wait until suitable capacity becomes available.

Can customers gain extra turns by creating more tenant IDs?

Yes, if the application trusts arbitrary client-supplied tenant identifiers. Bind scheduling identity to authenticated organizations and enforce account-level allocation rules where appropriate.

Should retries go to the front of a tenant queue?

Not automatically. Repeated failures could monopolize dispatch. Use bounded retries with delayed eligibility, and specify whether retry attempts consume the same allocation as new work.

Does using GenRelay eliminate the need for application scheduling?

No. Your application's customer boundaries, budgets, and service policies still need explicit enforcement. Apply this design around your integration without assuming undocumented platform scheduling guarantees.

Related posts

Join our DiscordAI video API fair scheduling: Tenant Queues and Limits — GenRelay