Skip to main content
Engineering Deep Dives

Building Scalable APIs with Django REST Framework

A
Adaeze Okafor

Jul 17, 2026 · 1 min read · 2 comments

Most API performance problems are not framework problems. They are query problems, pagination problems and "we never measured it" problems.

1. Paginate everything

Use cursor pagination for feeds and anything that grows. Offset pagination gets slower with every page and shows duplicates when rows are inserted mid-scroll.

2. Kill N+1 queries early

Add select_related for foreign keys and prefetch_related for many-to-many relations, then assert query counts in tests so regressions fail CI:

def test_list_is_constant_queries(client, django_assert_max_num_queries):
    with django_assert_max_num_queries(6):
        client.get("/api/orders/")

3. Throttle by intent

Separate throttles for login, search and writes. Abuse rarely looks like normal traffic.

4. Version from day one

A /v1/ prefix costs nothing today and saves a migration later.

None of this is glamorous. All of it held up in production.

Share WhatsApp Post LinkedIn
6 Like 3 Insightful 2 Fire
Sign in to react and save

Discussion (2)

Sign in to join the discussion.

Chisom Eze ·

The query-count assertion in CI is underrated. It caught two N+1 regressions for us last month.

Kojo Boateng ·

Cursor pagination plus a stable secondary sort key saved our infinite scroll.