Sitemap
Backend Engineers Club

Real-world backend engineering scalability, systems design, and the production failures nobody warns you about.

Member-only story

Your Django REST Framework Serializer Is Making 200 Database Queries Per Request

8 min readJul 11, 2026

--

Press enter or click to view image in full size
The Queries Hidden Inside the Serializer

We had an API endpoint that returned a list of 25 orders. The view was clean — one queryset, one serializer, paginated. In development, it responded in 180 milliseconds. In production, with real data and relationships, it took 4.7 seconds.

I opened django-debug-toolbar on the browsable API. 214 queries. For 25 orders.

If you’re not a Medium member, no worries! You can read the full story for free right here via : Friend Link

The view had select_related('customer'). The obvious N+1 was covered. But the serializer had a SerializerMethodField that accessed order.items.all(). Another nested serializer pulled item.product.category. A StringRelatedField on the product called __str__(), which accessed product.brand.name. Every one of these was a lazy load. Every lazy load fired a query. For every row.

25 orders × 4 items each × 2 lazy lookups per item = 200+ queries, generated entirely inside the serializer — invisible from the view.

The serializer wasn’t slow. The serializer was making the ORM do work the view never…

--

--

Anas Issath
Anas Issath

Written by Anas Issath

From Backend Developer to System Thinker

Backend Engineers Club
Backend Engineers Club

Published in Backend Engineers Club

Real-world backend engineering scalability, systems design, and the production failures nobody warns you about.