androidengineers.Book a session

Python services and data contracts

Async services, deadlines, and data contracts

articleSelf-paced

What you will learn

Python typing, Async I/O, HTTP errors, SQL transactions, Testing.

Engineering the capability

Separate an AI service into transport, domain logic, and dependency adapters. A request schema checks shape; domain rules check meaning. An integer quantity can pass schema validation while still violating a rule that quantities must be positive. Keep these checks independent of a model so a fake client can exercise them.

Async I/O lets a process handle other work while an operation waits. It does not make CPU-heavy parsing free. Bound concurrent model calls with a semaphore or worker pool, assign deadlines, and propagate cancellation. Otherwise a slow provider can accumulate work faster than you finish it.

Store request state explicitly when a task outlives one HTTP connection. Use a unique operation ID and database constraints to prevent duplicate records. A transaction can protect local writes; it cannot automatically roll back a remote model call. Design retries around that distinction.

Worked case

A service accepts 100 requests while the provider permits only 10 concurrent calls. Launching all 100 can cause rate limits and retry amplification. Admit at most 10, bound the waiting queue, and reject overload with a controlled response. If a request expires while queued, do not call the provider for it. Log queue time separately from execution time.

Put it into practice

Continue with the next lab: build a bounded inference gateway. Build the artifact, record the failure cases, and explain the tradeoff before moving on.

YOUR LEARNING JOURNEY

0 of 118 available lessons completed

Progress saved in this browser. No account needed.
Async services, deadlines, and data contracts | Agentic AI | Android Engineers