Helping lay the groundwork for our new company-wide API was exhilarating. In early 2022, I was on the team that developed a proof of concept and established standards for our new APIs. Fast forward to today and you’ll find over 150 endpoints spanning 12 product areas processing millions of requests daily. In this post, I’ll dive into one internal aspect of our APIs: Data Transfer Objects (DTOs). I’ll talk about why we chose attrs and how we use it. I’ll also show how we standardized the API implementation process for our developers including versioning of endpoints.
The API effort was herculean, spanning multiple engineering and product teams. It took discussions, technical design documents, and of course some bike-shedding! This quote from an early design document captures the vision:
“Klaviyo deserves a long-standing, consistent & flexible API that can serve developers inside and outside of Klaviyo for years to come while minimizing operational overhead for our internal developers and maximizing consistency and usability for our external developers.”
Setting the scene
Our API complies with the JSON:API spec. Chad Furman from the API team wrote a great post on why we chose JSON:API and how we use it. Our implementation is in Python, using the Django Rest Framework (DRF). We leverage DRF’s composable and flexible nature to customize its various components in our API.