{"canonical_url":"https://engineer.company/glossary/backend/","content_markdown":"# Backend\n\n## What it is\n\nA backend is the part of a software system that runs on machines its operator controls: it stores\nthe data, applies the rules about who may do what, and answers the requests that arrive from\nbrowsers, apps and other services. It is also written back end or back-end, and the same territory\nis often called the server side.\n\nIn HTTP terms, a backend is what RFC 9110 calls an origin server, \"a program that can originate\nauthoritative responses for a given target resource\". The W3C's Architecture of the World Wide Web\nadds the reader's view: a URI identifies a resource, and what travels to the browser is a\nrepresentation of it, data that encodes information about the resource's state. A customer sees an\norder page; the backend holds the order, the stock and the payment, and decides what goes into the\nreply.\n\nA backend usually exposes an API, a set of HTTP endpoints that a frontend, a mobile app or another\ncompany's system can call. The API is a contract: which paths exist, what each one accepts, what it\nreturns and which errors it can produce. The OpenAPI Specification is the common way to write that\ncontract down, as a programming language-agnostic description from which tools can generate clients,\ndocumentation and tests. Behind the API, the work is usually split into layers: request handling,\nbusiness logic and storage.\n\n## Why it matters\n\nThe first question is whether a system needs a backend running at request time at all. A page that\nis the same for every visitor can be generated once and served as files. A running backend earns its\nplace when a request has to change something or depends on who sent it: an order, a sign-in, a\nsearch over private data. It also carries a standing cost, since software that answers requests from\nthe internet has to be secured, patched and paid for.\n\nThe second is trust. Because the backend runs on machines its operator controls, it is the one place\na rule can be enforced. Anything the frontend checks can be skipped by someone who sends requests\ndirectly, so every rule that matters, from a price to a permission, is checked on the server against\nthe signed-in user and the specific record. The OWASP Application Security Verification Standard\nturns this into requirements a team can build to and test against.\n\nThe third is where the logic lives. A rule spread across a handler, a service class and a database\ntrigger has three places to change and three copies to drift apart. Some teams keep the rules in\napplication code and use the database as storage; others push rules and the shaping of data into the\ndatabase and keep the API thin. Either can work, as long as each rule has one home.\n\nThe fourth is the contract with clients. HTTP gives every response a status code with a defined\nmeaning, and clients, proxies and monitoring tools act on it. A 422 Unprocessable Content says the\nrequest was syntactically correct and in a supported format, but semantically wrong, such as a\nbooking dated in the past. RFC 9457 adds a standard body for errors, called problem details: a small\nJSON object with a type, a title, a status, a detail and an instance, sent as\n`application/problem+json`, so a client can tell one failure from another without parsing prose.\n\n## What it looks like in practice\n\nA relay race of transformations is the usual route from database to browser: the API unmarshals\nrows into structs, reshapes them and serialises them back to JSON. On one platform, the backend\n[lets the database build each response and passes it on untouched](/portfolio/designed-a-json-passthrough-from-postgres-to-api/).\nPostgreSQL functions assemble the whole response as JSON, where the data already is, and the Go\nhandler takes it as `json.RawMessage` and forwards it untouched. A small `QueryJSON` helper made\nthat the path of least resistance. The DTOs, the mappers and the response structs fell away, handler\ncode got dramatically shorter, and a change to what a function returns flows straight through to the\nclient without anyone editing handler code.\n\nRequests coming in get the same one-source treatment, through\n[a contract that starts at the database and runs outward](/portfolio/generated-the-api-contract-from-the-database-out/).\nOn the backend side, the schema and its functions define the shapes and the Go types define the\nAPI. Huma emits the OpenAPI description from those types, and the frontend's client, 44,076 lines\nof typed TypeScript, is generated from that description. The limits the user interface enforces on\na form come from the same place instead of being retyped into a validator. Every hop has a guard,\nso a field cannot change on one side only: the mismatch fails in a build, minutes after the change.\nRegenerating is the chore this costs, since every change to a shape the backend defines has to be\ncarried down the chain by generating each link after it again.\n\nAt the recorded design stage, this site made the opposite choice. It\n[was generated entirely at build time and needed no request-time application backend](/portfolio/built-a-multilingual-hugo-site-in-3-languages/).\nIts four requirements, including working in three languages and avoiding a separately billed\napplication service, led to that choice: a runtime application backend would need securing,\npatching and explanation on a privacy page. Beyond the recorded scoped JavaScript exception\nfor a portfolio filter, interactive features had to be solved at build time or omitted.\nThis describes the recorded design stage, not the current site's inventory or implementation;\nit does not mean hosting had no cost.\n\n## Where it goes wrong\n\nBackend faults tend to stay quiet until a request arrives that nobody planned for.\n\n**A user changes a record that belongs to someone else.** The endpoint checks that the caller is\nsigned in and then loads whatever ID the URL names, so editing `/invoices/1041` to `/invoices/1042`\nin a request is all it takes. Check ownership or permission on the server for every object a request\ntouches, in one place every handler passes through, and keep a test that asks for another account's\nrecord and expects a 403 or a 404.\n\n**An action happens twice.** A link that cancels something through a GET request is followed by a\ncrawler or a browser that prefetches pages, and the action runs without anyone clicking. RFC 9110\ndefines GET, HEAD, OPTIONS and TRACE as safe so that spiders and pre-fetching can work without fear\nof causing harm. The other route is a retry: a payment request times out, the client sends it again,\nand the customer pays twice. Put every change of state behind POST, PUT, PATCH or DELETE, and give\nwrites that may be retried a key the server remembers, so the second copy returns the result of the\nfirst.\n\n**Every error comes back as a 500, or as a 200 with an error message inside.** One catch-all handler\nreports every failure the same way, so monitoring counts typing mistakes as outages and retry logic\nrepeats requests that will fail every time. Map each failure to the status code that describes it:\n400 or 422 for bad input, 401 and 403 for identity and permission, 404 for a missing resource, 409\nfor a conflict, and 5xx only for the server's own faults. Send the details as problem details:\n\n```json\n{\n    \"type\": \"https://example.com/problems/booking-in-past\",\n    \"title\": \"Booking date is in the past\",\n    \"status\": 422,\n    \"detail\": \"The date 2026-10-01 is before today.\",\n    \"instance\": \"/bookings/8812\"\n}\n```\n\nRFC 9457 says problem details \"are not a debugging tool for the underlying implementation\", so stack\ntraces and SQL stay in the server's logs.\n\n**Pages slow down as the data grows.** A handler loads a list of orders and then queries the\ncustomer for each one, so a page of 50 orders makes 51 round trips to the database. It feels quick\nin development with ten rows and drags in production with ten thousand. Fetch related data in one\nquery with a join, or let the database assemble the whole response, and watch the number of queries\nper request as closely as the response time.\n\n## Further reading\n\n- [Architecture of the World Wide Web, Volume One](https://www.w3.org/TR/webarch/) — the W3C\n  Recommendation on resources, representations, and safe and unsafe interactions.\n- [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110) — the IETF standard for\n  methods, status codes and what makes a request safe or idempotent.\n- [OpenAPI Specification](https://spec.openapis.org/oas/latest.html) — the language-agnostic format\n  for describing an HTTP API, read by people and by code generators.\n- [RFC 9457: Problem Details for HTTP APIs](https://www.rfc-editor.org/rfc/rfc9457) — the standard\n  JSON shape for machine-readable error responses.\n- [OWASP Application Security Verification Standard](https://owasp.org/projects/asvs) — a list of\n  security requirements for building and testing web applications.\n\n\u003chttps://engineer.company/glossary/backend/\u003e\n","date_modified":"2026-11-12T05:34:23Z","description":"What a backend does, when a site needs one at all, where business rules should live, and how HTTP APIs on the server side most often go wrong.","formats":{"gemtext":"https://engineer.company/glossary/backend/index.gmi","gopher":"https://engineer.company/glossary/backend/gophermap","html":"https://engineer.company/glossary/backend/","json":"https://engineer.company/glossary/backend/index.json","markdown":"https://engineer.company/glossary/backend/index.md","pdf":"https://engineer.company/glossary/backend/index.pdf"},"kind":"page","language":"en","title":"What is a backend?","url":"https://engineer.company/glossary/backend/","version":1}