Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
Python & Django

An API Other Systems Can Depend On

Last updated:

Validate at the boundary

Every piece of data entering your service should be validated and converted into a known shape before any business logic touches it. Python's typing and validation libraries make this straightforward.

A service that validates at the boundary can trust its own internals. One that validates ad hoc throughout is where the subtle bugs live.

Consistent errors

  1. Meaningful status codes — not 200 with an error in the body
  2. A single error shape used everywhere
  3. A machine-readable code alongside the human message
  4. Field-level detail for validation failures
  5. No internal detail leaked in production error messages

Version before you have consumers

Adding versioning after the first consumer means either breaking them or maintaining an unversioned path forever. A path prefix decided at the start costs nothing.

Then be explicit about what constitutes a breaking change, and communicate deprecations with real dates.

Document from the code

  • Generated from the schemas, so it cannot drift
  • Example requests and responses for every endpoint
  • Every error code listed with its cause
  • Authentication explained with a working example
  • Rate limits stated explicitly

The test of good API documentation is whether someone can build against it without contacting you. Most fail that test.

Operational requirements

RequirementWhy
Health endpointLoad balancers and monitoring need it
Request identifiersTracing a single call through logs
Structured loggingSearchable when something goes wrong
Rate limitingIncluding for internal consumers
Graceful shutdownDeployments without dropped requests

Frequently asked questions

Which Python framework for APIs?

Several are good and differ mainly in style and async support. Consistency and proper structure matter more than the choice.

Should we use async?

For services doing many concurrent external calls, it helps considerably. For database-bound work, the benefit is smaller.

How do we handle authentication?

Tokens for service-to-service, standard flows for user-facing. Do not invent your own scheme.

What about rate limiting internal consumers?

Yes. Internal loops cause outages at least as often as external abuse does.

Keep reading

Building a service other systems will depend on?

The decisions made before the first consumer are the ones you live with. Happy to review a design.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Custom Software DevelopmentWeb DevelopmentMachine Learning