Benchmark methodology
GritvsDjango

Grit vs Django

Django REST Framework is the Python answer to the same problem Grit solves: a CRUD API with an admin attached. This measures it behind gunicorn with gevent workers, which is how Django is actually deployed.

Python 3.12, Django 5.1, gunicorn + gevent (9 workers), psycopg pool · v5.1 + Django ORM

What you should end up with

ScenarioGritDjangoRatio
show
GET /api/v1/products/:id
5,983 req/s
6.0 ms · neither saturated
811 req/s
73.4 ms · its own ceiling
7.38×
write
POST /api/v1/products
5,901 req/s
6.2 ms · neither saturated
913 req/s
65.1 ms · its own ceiling
6.46×
list
GET /api/v1/products?page=N&page_size=20
1,094 req/s
36.9 ms · database-bound
379 req/s
118.5 ms · its own ceiling
2.89×
mixed
a weighted blend of the three above
1,163 req/s
36.2 ms · database-bound
481 req/s
77.4 ms · its own ceiling
2.42×

Both figures come from the same run, minutes apart. Your absolute numbers will differ (different CPU, different disk, different background load) and so will ours: Grit's single-row read measured 4,536 req/s in the Bun pair and 8,509 in the Express pair from an identical binary, as hours of write scenarios accumulated in Postgres. The ratio is what should survive. If it does not, something in the setup differs and the steps below are where to look.

How Django is kept from being handicapped

A benchmark is only worth publishing if the loser was given every reasonable advantage. These are the specific decisions made for this framework, and each one is worth saying out loud on camera.

  • gunicorn with 9 gevent workers: gunicorn’s own recommended formula of 2 × CPU + 1. Not `manage.py runserver`, which is single-threaded and warns you not to use it in production.
  • gevent rather than sync workers. The workload is IO-bound on Postgres, and sync workers would block an entire worker per in-flight query.
  • Django 5’s built-in connection pooling is on. Without it every request opens a connection and Postgres forks a backend: the same connection churn this benchmark found in Grit, and it would cost Django just as much.
  • The middleware stack is trimmed to CommonMiddleware. Sessions, auth, messages and CSRF all cost time per request and do nothing for an unauthenticated JSON API.
  • DRF’s browsable API renderer is off: it is a development convenience that costs content negotiation on every request and nobody serves it in production.
  • Function-based `api_view` rather than a ModelViewSet, because a viewset adds routing and permission machinery Grit’s handler has no equivalent of.
  • The model is `managed = False` against the shared table, so Django cannot quietly disagree with the others about column types or indexes.
  • Access logging off, matching every other framework here.

Reproduce it, start to finish

  1. 1

    Install the two tools you need

    Docker runs every app and the database. k6 generates the load. Nothing else is required: you do not need Go, PHP, Python, Node or Bun installed locally, because every framework builds inside a container.

    # macOS
    brew install k6
    # Windows
    winget install k6 --source winget
    # Linux
    sudo gpg -k && sudo gpg --no-default-keyring \
    --keyring /usr/share/keyrings/k6-archive-keyring.gpg \
    --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
    echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" \
    | sudo tee /etc/apt/sources.list.d/k6.list
    sudo apt-get update && sudo apt-get install k6
    k6 version
    docker --version
  2. 2

    Clone the harness

    Everything below lives in the benchmarks directory of the Grit repository: the compose file, the k6 script, the seed data, and each framework’s application.

    git clone https://github.com/MUKE-coder/grit.git
    cd grit/benchmarks
  3. 3

    Start Postgres and create the databases

    One Postgres instance is shared by every framework, tuned once, with 8 CPUs: deliberately more than any application gets, so the database is never what gives out first. Each framework gets its own database so their schemas cannot collide.

    docker compose up -d postgres
    for db in bench_grit bench_encore bench_bun bench_express bench_nextjs bench_laravel bench_django; do
    docker compose exec -T postgres psql -q -U bench -d bench -c "CREATE DATABASE $db;"
    done
  4. 4

    Create the table and load identical rows

    This is the single most important step for a fair result. Every framework gets the same table, created from the same SQL file, holding the same 10,000 rows with the same UUIDs. Letting each ORM run its own migration would mean comparing schemas, not frameworks: Eloquent, Django and GORM disagree about integer widths, timestamp precision and which columns get indexed.

    for db in bench_grit bench_encore bench_bun bench_express bench_nextjs bench_laravel bench_django; do
    docker compose exec -T postgres psql -q -U bench -d $db < seed/schema.sql
    docker compose exec -T postgres psql -q -U bench -d $db < seed/products.sql
    done
    # every one should print 10000
    for db in bench_grit bench_encore bench_bun bench_express bench_nextjs bench_laravel bench_django; do
    docker compose exec -T postgres psql -tA -U bench -d $db -c "SELECT count(*) FROM products;"
    done

    If any of these prints something other than 10000, stop and fix it. A benchmark where one side has more rows than another is measuring the row count.

  5. 5

    Look at the Django app

    Three files worth reading on camera: the settings (note how short the middleware list is), the views, and the serializer.

    cat django-bench/bench/settings.py
    cat django-bench/products/views.py
    cat django-bench/products/serializers.py
  6. 6

    Note the serializer coercion

    DRF renders DecimalField as a quoted string by default. Every other framework here emits price as a JSON number, so the serializer overrides it: otherwise the payloads differ and the comparison is void.

    class ProductSerializer(serializers.ModelSerializer):
    price = serializers.FloatField()
    stock = serializers.IntegerField()
    version = serializers.IntegerField()
  7. 7

    Note managed = False

    The table comes from seed/schema.sql, shared with every other framework. Django is pointed at it rather than migrating its own, so there is no chance of a column type or an index differing between runs.

    class Meta:
    db_table = "products"
    managed = False
  8. 8

    Build and start it

    Python 3.13 slim, gunicorn with gevent workers.

    docker compose build django
    docker compose up -d django
    docker compose logs django | head -5
  9. 9

    Check every framework is on an ORM, not raw SQL

    This is the fairness decision that matters most after the shared schema. Grit’s generated handlers use GORM and you cannot swap that out, so measuring any framework against hand-written SQL compares an ORM to no ORM, which flatters that framework for a reason that has nothing to do with it. Express on raw pg measured 2,000 req/s on writes; the same Express on Prisma measured 773. Same framework, same machine, same test.

    # Grit GORM apps/api/internal/models/product.go
    # Laravel Eloquent laravel-bench/app/Models/Product.php
    # Django Django ORM django-bench/products/models.py
    # Express Prisma express-bench/prisma/schema.prisma
    # Next.js Prisma nextjs-bench/prisma/schema.prisma
    # Bun Drizzle bun-bench/schema.ts
    # Encore Drizzle encore-bench/products/schema.ts
    grep -rl "prisma|drizzle|Eloquent|models.Model" express-bench nextjs-bench bun-bench encore-bench django-bench laravel-bench 2>/dev/null | head

    If you swap any of these for raw SQL the numbers move enough to change the conclusion. That is the single easiest way to make this benchmark say whatever you want it to say.

  10. 10

    Prove the two apps return the same bytes

    Before measuring anything, confirm the framework you are testing returns exactly what Grit returns for the same record. If the payloads differ, say a missing field or a price as a string instead of a number, then the two are doing different amounts of work and the comparison is void.

    ID=$(python -c "import json;print(json.load(open('seed/ids.json'))[0])")
    for app in grit django; do
    echo "--- $app"
    docker run --rm --network benchmarks_default curlimages/curl -s \
    "http://$app:8080/api/v1/products/$ID"
    echo
    done

    This is the step most benchmarks skip, and it is the one that decides whether the rest means anything. Show it on camera.

  11. 11

    Run the benchmark

    Three repetitions of four scenarios, one application at a time with the others stopped. Each run resets the dataset first, discards a warm-up, and samples container CPU while the load is actually running.

    APPS="grit django" REPS=3 ./final.sh
    python aggregate.py

Reading your own results

Django with DRF is the slowest in this comparison, which is not a surprise and not really the point: Django is chosen for the admin, the ORM and the ecosystem, not for throughput. What the numbers are useful for is knowing where the ceiling is before you need to care.

aggregate.py prints the app container's CPU and Postgres's CPU next to every row. That pair is what tells you whether a number is a real ceiling. If the app is pinned near 400% then you are seeing its limit. If the app is idling while Postgres is near 800%, the database gave out first. That row is a floor, the framework would go faster on a bigger database, and quoting it as “X does N req/s” overstates what you measured.

The other guides