esedark
server infrastructure coordinating queued jobs for mobile devices

mobile bots / queues / android / workers / traceability

How to design work queues for mobile bots

A mobile queue is not just a list of pending actions. It is the control plane that decides which device owns a job, how failures recover and whether operators can explain every result.

Mobile automation becomes unreliable when an API sends commands directly to whichever Android phone appears free. Devices are stateful: an app may be logged out, a system dialog may cover the screen or a previous session may still own the device. A work queue creates a controlled boundary between business requests and physical execution.

The goal is not maximum throughput at any cost. The goal is predictable work with limited retries, explicit permissions and enough evidence to diagnose a failure. This complements a central Android device controller and a disciplined UiAutomator2 execution layer.

A practical mobile queue architecture

API -> job validator -> durable queue
                         -> device scheduler
                         -> one-device worker
                         -> Appium / ADB
                         -> result and evidence store

The API should accept intent, not low-level taps. The validator checks required data, authorization and workflow limits before publishing. The scheduler chooses a compatible device, while the worker owns that device for the complete job. Results, timestamps, screenshots and classified errors return to a separate store.

Use separate queues when jobs have materially different requirements: app version, locale, account type, physical-device capability or approval level. Do not create one queue per tiny variation; routing metadata and a small number of well-defined queues are easier to operate.

Device ownership must be exclusive

One worker should hold a lease on one device while a job runs. The lease needs an expiry and heartbeat, but another worker must not take over merely because a step is slow. If ownership is ambiguous, two jobs can alter the same app state and neither result remains trustworthy.

Store the job ID, worker ID, Android serial, account or tenant reference, Appium session and lease timestamps together. That correlation turns an intermittent UI failure into an incident you can reconstruct.

Design jobs for idempotency and checkpoints

A mobile action cannot always be perfectly idempotent. Tapping “send” twice is different from reading a screen twice. Make the surrounding workflow idempotent: give every request a unique key, detect completed work before retrying and checkpoint after irreversible steps.

Classify steps as read-only, reversible or state-changing. Reading public information can normally retry within respectful rate limits. Publishing, messaging, buying or changing an account should have stricter authorization, platform-compliance checks and often a human approval boundary. A queue must never become an excuse to bypass service terms or user consent.

Retries need reasons, not optimism

Retry a temporary USB disconnect differently from a missing selector. Infrastructure errors may recover after reconnecting the device; invalid input should fail immediately; a changed screen needs review or a revised automation version. Blind retries multiply damage and hide the real failure rate.

Use a small retry budget, exponential backoff where appropriate and a dead-letter queue for jobs requiring inspection. Save the last safe checkpoint so recovery does not repeat a state-changing action.

Common mistakes

  • letting multiple workers share one device without a lease
  • placing credentials or large screenshots inside queue messages
  • using one generic error for selector, network and device failures
  • retrying every exception with the same delay
  • mixing scheduling, Appium control and business rules in one process
  • reporting success before verifying the expected final state
  • keeping no audit trail for sensitive or outbound actions

Practical checklist

  • define a versioned job schema and unique idempotency key
  • validate authorization and workflow limits before enqueueing
  • lease each device exclusively with heartbeat and expiry
  • record job, worker, device and session identifiers together
  • separate transient, permanent and review-required failures
  • cap retries and maintain a dead-letter review process
  • capture current activity, screenshot and app version on failure
  • encrypt secrets and pass references rather than credentials
  • measure queue age, execution time, recovery rate and device health
  • document public-data, consent and platform-policy boundaries

Observability and stability

Queue length alone tells you very little. Monitor oldest-job age, time waiting for a compatible device, execution duration by workflow, retry reasons, dead-letter volume and device availability. Pair those metrics with structured logs as described in the minimum monitoring stack.

Deploy workflow versions gradually. Keep the version on every job so old and new behavior can be compared, and pause a workflow when its error rate crosses a defined threshold. Stability comes from controlled degradation, not from pretending every phone is always healthy.

When hiring a technical person makes sense

Technical help is valuable when manual recoveries consume the team, duplicate actions appear, queue latency is unpredictable or nobody can trace a job from API request to device result. Those symptoms usually require architecture and operating rules, not another retry loop.

A specialist can define schemas, leases, recovery states, observability and compliance boundaries, then decide what should stay manual. See my technical services or fractional CTO support if the system spans backend, queues and Android devices.

Final takeaway

A good mobile-bot queue makes execution boring: one validated job, one compatible device, one accountable worker and one traceable result. If your current setup loses jobs or repeats actions, contact me with the device count, workflow types and recent failure examples. I can help turn them into an operable queue design.