jargon

Backend & systems·topic 8 of 13

API and interface design

The contract is the part you cannot refactor unilaterally, because somebody else's code is holding the other end. Most of this section is about changing things without breaking callers.

Read in order · tick what you already know

  1. 01

    you put one component in front of all the services to do auth, rate limiting and routing once instead of in each of them.

    API gateway

  2. 02

    you build a separate thin API for the mobile app so it stops being shaped by whatever the web client needed.

    Backend for frontend

  3. 03

    you make the endpoint a PUT with a client-chosen id, so a nervous client can send it three times without creating three records.

    Idempotent HTTP method

  4. 04

    the mobile client needs two fields and the endpoint returns a forty-field object with three nested collections.

    Over-fetching

  5. 05

    you ask for page 400 and the database dutifully reads and discards the first eight thousand rows to get there.

    Offset pagination

  6. 06

    you return an opaque token pointing at the last row, so page fifty costs the same as page one and nothing shifts under the client.

    Cursor pagination

  7. 07

    you cap each client at a hundred requests a minute and start returning 429 once they go over.

    Rate limiting

  8. 08

    you let clients save up allowance while idle and spend it in a burst, as long as the long-run average stays under the limit.

    Token bucket

  9. 09

    the client makes a request and you hold it open for thirty seconds, only answering when something actually happens.

    Long polling

  10. 10

    you upgrade the connection once and then push messages in both directions without a new request each time.

    WebSocket

  11. 11

    instead of your client polling for changes, you POST to a URL they gave you whenever something happens.

    Webhook

  12. 12

    you renamed the field and every client that was reading it starts getting nulls in production.

    Breaking change

  13. 13

    you add the field as optional so the clients that have never heard of it keep working unchanged.

    Backward compatibility

  14. 14

    your parser ignores fields it does not recognise, so a newer producer can add one without breaking you.

    Forward compatibility

  15. 15

    you put /v2 in the path because the change you need cannot be made without breaking the callers on /v1.

    API versioning

  16. 16

    you change the message format and have to make sure the consumers still on the old schema can read the new messages.

    Schema evolution

  17. 17

    you announce the endpoint is going away, keep it running for six months, and watch the traffic to find out who is still on it.

    Deprecation window

  18. 18

    you wrap the legacy system's awkward model in a translation layer so its concepts do not leak into your new code.

    Anti-corruption layer