Staggered, exclusive, queued: scheduling dozens of cron jobs without shared-resource collisions

    Running dozens of automation jobs in the same time window looks efficient until they share a single channel, port, quota, or working directory. This article walks through three real failure modes—channel contention, browser-port mix-ups, and in-job tab overwrites—and a reusable checklist: inventory exclusive resources, stagger or serialize, isolate namespaces, verify end state, and make failures observable.

    Lead with the conclusion

    Packing dozens of automation jobs into the same window feels reasonable: idle machines should be used, and running everything together should save time. Concurrent jobs rarely fail because they cannot run together. They fail because some resources exist only once. There is one channel, a handful of ports, shared quotas and tokens, and a shared working directory. Wherever a resource is exclusive, unordered concurrency is trampling.

    We re-orchestrated sixty-plus scheduled jobs around three ideas: stagger, exclusive use, and queue. The three incidents below are the reasons.

    Pitfall 1: Many jobs hit the same minute, and there is only one channel

    What happened

    After the system moved from manual posting to auto-filling drafts, distribution jobs for several product lines were created. The first schedule was unplanned: everything clustered around 8:00 a.m.

    The bottleneck was the control channel. The draft-filling tool is a browser extension that exposes a single local communication endpoint (local WebSocket on fixed port 9527). Behavior:

    • Whoever connects first holds the channel;
    • A second job either errors or hijacks the previous job’s command stream.

    Failures were subtle: job A’s copy landed in job B’s draft box, or both jobs reported “push succeeded” while the backend had no content. Errors often surfaced only at human review or after publish, so investigation and rework were expensive.

    Fix: stagger the schedule so concurrency becomes serial

    If the channel is exclusive, only one job may use it at a time. Morning distribution became a single timeline:

    Time Job Target
    07:15 Domestic distribution (line B) Drafts on seven platforms
    08:15 Domestic distribution (line A) Drafts on seven platforms
    08:45 Domestic distribution (line C) Drafts on seven platforms

    Overseas jobs were likewise placed at 06:15 / 06:20 / 06:25. One channel, one job, at least ten minutes between runs.

    Large gaps do not lower efficiency. One collision costs log digging, draft-box audits, deleting wrong drafts, and reruns—enough human time for many staggered cycles. Staggering saves rework, which is the real efficiency.

    Generalization

    The same rule applies wherever jobs share a serial entry:

    • Job sets that share one database write path: split by business window;
    • Callers that share one third-party quota (rate limit): token bucket or time-slice queue;
    • Batch jobs that share one printer, signer, or uploader: global mutex or message-queue serialization.

    Test: if two jobs use this resource at once, do you get dirty data or overwrite? If yes, stagger or lock.

    Pitfall 2: Unplanned ports, jobs fighting over one browser

    What happened

    Automation depends on browser instances with remote-debug ports. A port is an address; behind it sits a login session.

    Without a port map, jobs connected to the default. Job A could attach to line B’s browser—someone else’s account. Content went out under the wrong identity.

    This is worse than a blocked channel: a blocked channel fails to send; a wrong port sends to the wrong place. Damage is often noticed after data is stored or public.

    Fix: one business line, one port, hardcoded config

    Principle: one brand, one port. Three steps:

    1. Fixed port assignment: 9222, 9223, 9224 bound to specific lines;
    2. Hardcoded ports in job scripts: no dynamic discovery; addresses are fixed in the script;
    3. Hardcoded user-data dirs in launch scripts: each instance has its own directory, session, and proxy.

    Illustrative config:

    1. # launch script (pseudocode)
    2. BROWSER_A = launch_browser(port=9222, user_data_dir="/data/profile_a", proxy="proxy_a")
    3. BROWSER_B = launch_browser(port=9223, user_data_dir="/data/profile_b", proxy="proxy_b")
    4. # job script (pseudocode)
    5. task_brand_a.connect("127.0.0.1:9222") # hardcoded; no dynamic probing

    Generalization

    “Wrong port = posting with someone else’s account” means session and context are implicit resources. Misconnect does not always error; it silently pollutes data. The same pattern appears when:

    • Test / staging / production share one config template and env vars are not isolated;
    • Service instances share one local cache directory and overwrite each other;
    • Concurrent CI on one runner reuses a dirty workspace and mixes previous artifacts.

    Give each context its own namespace (port, directory, env prefix) and prefer hardcoding over auto-discovery. In a shared environment, discovery often finds the wrong thing.

    Pitfall 3: Inside one browser, a later page displaces an earlier one

    What happened

    Some conflicts are inside a single job.

    One push flow opened several platform draft pages, then navigated “open the platform home to confirm login.” The health check reused the same tab and replaced the draft pages—three drafts were navigated back to home. The job still reported success.

    Each step succeeded; later steps overwrote earlier results. Step success is not goal success.

    Fix: isolate state and verify the end state

    Two changes:

    1. Separate open from check: login checks run in a dedicated tab (or a dedicated headless instance), then close; do not reuse business-page context;
    2. End-state checks instead of step receipts: after push, re-enumerate open draft pages and assert “expected N draft pages, N present, content non-empty.” Any miss is failure and alert—do not trust intermediate success.

    Pseudocode:

    1. pages = [open_draft(p) for p in platforms] # open business pages
    2. check_login_in_new_tab() # independent tab, close after use
    3. verify(final_state=pages, expect_count=len(platforms)) # end-state check

    Generalization

    Internal self-collision treats shared mutable state as independent. Similar cases:

    • cd to directory A, then cd to B, without finishing A;
    • After upload, reuse the same temp filename for a check download and overwrite the original;
    • Change config, restart to verify, then the verify path rewrites the config.

    Two counters: state isolation (independent context per logical stage) and end-state verification (business outcome, not intermediate return codes).

    A reusable scheduling checklist

    From the three incidents:

    1. Inventory exclusive resources: channels, ports, tokens, quotas, directories, accounts, sessions—anything that breaks if two jobs use it at once;
    2. Stagger or serialize: for truly non-concurrent resources, timeline by priority, with buffer ≥ longest job duration;
    3. Namespace isolation: dedicated ports, dirs, and account context per job; hardcode config; disable dynamic discovery;
    4. End-state as the source of truth: files exist, records persist, pages are reachable—not mid-step receipts;
    5. Observable failure: failed checks must alert, not silent retries that hide the issue.

    Stagger, exclusive use, and queue are plain words for a scaling fact: when job count goes from a few to dozens, the bottleneck is not CPU; it is order around shared resources. With that order, automation saves people instead of consuming them in a different way.