How Candid sped up API development by 50% by going schema first
2 min read
Background on Candid: Candid provides an API for medical billing (think Stripe but for healthcare payments instead of credit cards). They also have a UI that consumes the API.
Devs waste time writing boilerplate code. With every new endpoint, a backend engineer writes Pydantic models and FastAPI routes on the backend. And then, a frontend engineer writes the same types & networking logic on the frontend. If Candid offered SDKs to their customers, they’d have to write the same code inside each SDK. Of course, their Postman collection and API reference docs need updating too. This work is repetitive, boring, and not a good use of engineering time.
Multiple sources of truth == drift bugs. Inevitably, the API’s multiple sources of truth (backend, frontend, Postman, docs, and SDKs) get out of sync. This causes runtime bugs, and the debugging costs even more engineering time.
Here at Fern, we’re productizing schema-first API development. At Candid, it looks something like this:
Define schema: When one of the backend engineers needs to change an API, they edit the API Definition (yaml files similar to OpenAPI).
Generate code: They run
fern generate, which generates all the Pydantic models and the FastAPI routes. Fern integrates well with mypy, so if they don’t implement the API correctly, they’ll get a compile error.
Write business logic: The dev then implements the business logic and makes a PR.
Generate frontend SDK: When the PR merges into
master, Fern has a CI task to generate and publish a TypeScript client that is used by the frontend team. This client includes all the types and networking logic, so it’s generally a one-liner to hit the API.
All in all, it’s pretty sweet. As of 2/5/23, 95,000 lines of Candid’s backend and 30,000 lines of their frontend are auto-generated by Fern. Their devs waste almost no time writing boilerplate, and they have a single source of truth for their entire API.
API docs: Candid is going to use Fern to sync their API definition with their API docs, so their docs are always up to date.
Customer-facing SDKs: Candid is going to use Fern to generate SDKs for their customers. This will speed up the process of integrating with the Candid API.
Interested in using Fern? Please reach out.
Fern is open source! Check us out on GitHub.