Designed a JSON passthrough from Postgres to API
Designed a JSON passthrough architecture where PostgreSQL functions
return complete JSON forwarded verbatim by the Go API, eliminating
intermediate unmarshalling and decoupling the frontend from schema
changes.
2025

Situation. The usual way data gets from a database to a browser is a
relay race of transformations. The database hands the API rows, the
API unmarshals them into structs, reshapes them, serialises them
back to JSON, and only then do they go out. Every one of those hops
is code you write, code you test, and one more place where the API's
idea of the data and the database's idea of it can drift apart.

Task. The idea was to skip the relay race. If the database could
return the finished response, the API could just pass it along, and
the frontend could depend on the database's shape directly instead
of on a hand‑maintained copy of it living in Go.

Action. So it was built as a straight passthrough. The PostgreSQL
functions assemble the whole response as JSON — the shaping is a SQL
concern, done where the data already is. The Go handler takes that
back as json.RawMessage and forwards it untouched; it never
decomposes it, never re‑encodes it. A small QueryJSON helper made
that pattern the path of least resistance rather than something you
had to remember to do. What fell out was all the intermediate
machinery a conventional layered API collects — the DTOs, the
mappers, the response structs.

Result. Handler code got dramatically shorter, and more to the point
the frontend stopped being coupled to Go. Change what a function
returns and the new shape flows straight through to the client
without anyone editing a line of handler code. Fewer moving parts,
and one whole category of layer‑to‑layer drift simply doesn't exist
here.

Categories:
1Platform Architecture	/categories/platform-architecture/	software.engineer.company	70
1Backend Engineering	/categories/backend/	software.engineer.company	70
1APIs & Integration	/categories/api/	software.engineer.company	70
1Databases	/categories/databases/	software.engineer.company	70
1PostgreSQL	/categories/postgresql/	software.engineer.company	70
1SQL	/categories/sql/	software.engineer.company	70
1Performance Tuning	/categories/performance/	software.engineer.company	70

Services:
1Platform & Solution Architecture	/services/platform-architecture/	software.engineer.company	70
1Backend & API Development	/services/backend-development/	software.engineer.company	70
1AI Agent Tools & MCP Servers	/services/ai-tools/	software.engineer.company	70
1Database Design & Modeling	/services/database-design/	software.engineer.company	70

hThis page on the web	URL:https://software.engineer.company/portfolio/designed-a-json-passthrough-from-postgres-to-api/	software.engineer.company	70
