Skip to content

RobithYusuf/k6-backend-benchmark

Repository files navigation

Backend Framework Performance Comparison

Load testing comparison of multiple backend frameworks/languages using k6.

Test Results Summary

Rank Framework Throughput Avg Response Runtime
πŸ₯‡ Bun Native 30,733 req/s 32ms Bun (Zig)
πŸ₯ˆ Go 28,597 req/s 35ms Go
πŸ₯‰ Node.js Native 27,899 req/s 36ms Node.js
4 Rust (Actix) 27,458 req/s 36ms Rust
5 Hono 23,325 req/s 43ms Node.js
6 Express.js 8,361 req/s 119ms Node.js
7 Next.js API 3,376 req/s 295ms Node.js
8 Laravel Octane 1,124 req/s 877ms PHP

Throughput Visualization

Bun Native      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  30,733 req/s
Go              β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ      28,597 req/s
Node.js Native  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ       27,899 req/s
Rust (Actix)    β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ        27,458 req/s
Hono            β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ              23,325 req/s
Express.js      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                                      8,361 req/s
Next.js API     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                                              3,376 req/s
Laravel Octane  β–ˆβ–ˆ                                                 1,124 req/s

Test Methodology

Configuration

Parameter Value
Virtual Users 1,000 concurrent users
Duration 30 seconds
Endpoint /api/v1/health (simple JSON response)
Environment Docker containers on local machine (Apple M1/M2)

What We Measured

  • Throughput - Requests per second (req/s)
  • Response Time - Average, p95, p99 latency
  • Success Rate - Percentage of successful requests (HTTP 200)

Project Structure

script-k6-testing/
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ .gitignore
β”‚
β”œβ”€β”€ bun-test.js               # Bun native (port 3011)
β”œβ”€β”€ go-test.js                # Go net/http (port 3006)
β”œβ”€β”€ hono-test.js              # Hono (port 3010)
β”œβ”€β”€ express-test.js           # Express.js (port 3005)
β”œβ”€β”€ nextjs-test.js            # Next.js API (port 3009)
β”œβ”€β”€ nodejs-native-test.js     # Node.js native (port 3008)
β”œβ”€β”€ rust-actix-test.js        # Rust Actix-web (port 3007)
β”œβ”€β”€ laravel-octane-test.js    # Laravel Octane (port 8000)
β”‚
β”œβ”€β”€ servers/
β”‚   β”œβ”€β”€ bun/                  # Bun native server
β”‚   β”œβ”€β”€ go/                   # Go server
β”‚   β”œβ”€β”€ hono/                 # Hono framework server
β”‚   β”œβ”€β”€ express/              # Express.js server
β”‚   β”œβ”€β”€ nextjs/               # Next.js 14 with API routes
β”‚   β”œβ”€β”€ nodejs-native/        # Node.js native HTTP server
β”‚   └── rust-actix/           # Rust Actix-web server
β”‚
└── _private/                 # Private test scripts (gitignored)

How to Run

Prerequisites

1. Start a Server

# Example: Start Bun server
cd servers/bun
docker-compose up -d --build

# Verify it's running
curl http://localhost:3011/api/v1/health

2. Run the Test

# Run k6 test (from root directory)
k6 run bun-test.js

3. Stop the Server

cd servers/bun
docker-compose down

Server Ports

Framework Port
Express.js 3005
Go 3006
Rust (Actix) 3007
Node.js Native 3008
Next.js API 3009
Hono 3010
Bun Native 3011
Laravel Octane 8000

Key Insights

Why Bun is Fastest?

  1. Zig-based runtime - Low-level language like Rust/C
  2. JavaScriptCore engine - Safari's JS engine, optimized differently than V8
  3. Built-in HTTP server - No external dependencies
  4. Zero-copy optimizations - Minimal memory allocation

Node.js Framework Comparison

Framework Throughput vs Native
Node.js Native 27,899 req/s 1x
Hono 23,325 req/s 0.84x
Express.js 8,361 req/s 0.30x
Next.js API 3,376 req/s 0.12x

Performance Tiers

Tier Throughput Frameworks
Tier 1 25,000+ req/s Bun, Go, Node.js Native, Rust
Tier 2 10,000 - 25,000 req/s Hono
Tier 3 5,000 - 10,000 req/s Express.js
Tier 4 < 5,000 req/s Next.js API, Laravel Octane

Customizing Tests

Change VUs and Duration

export const options = {
  vus: 500,
  duration: '60s',
};

Stress Test with Stages

export const options = {
  stages: [
    { duration: '1m', target: 100 },
    { duration: '3m', target: 100 },
    { duration: '1m', target: 500 },
    { duration: '2m', target: 500 },
    { duration: '1m', target: 0 },
  ],
};

Disclaimer

⚠️ Hasil benchmark ini BUKAN tolak ukur mutlak untuk memilih framework.

Hasil testing ini hanya mengukur raw performance dari masing-masing framework dengan endpoint sederhana (health check). Performa aplikasi di dunia nyata dipengaruhi oleh banyak faktor lain:

Faktor Pengaruh
Database Query optimization, indexing, connection pooling
Caching Redis, Memcached, in-memory cache
Server CPU, RAM, SSD/NVMe, network bandwidth
Infrastructure Load balancer, CDN, auto-scaling
Code Quality Algorithm efficiency, N+1 queries, memory leaks
Business Logic Complexity of operations, external API calls
Framework Features ORM, validation, middleware, authentication

Catatan Penting

  • Laravel mungkin lebih lambat di benchmark, tapi menyediakan fitur lengkap (ORM, queue, caching, authentication) yang mempercepat development
  • Bun/Go/Rust sangat cepat, tapi butuh effort lebih untuk implementasi fitur yang sama
  • Framework yang "lambat" di benchmark bisa sangat cepat di production dengan optimasi yang tepat
  • Pilih framework berdasarkan kebutuhan project, skill tim, dan ekosistem, bukan hanya benchmark

Faktor yang Tidak Diuji

  • Database queries (MySQL, PostgreSQL, MongoDB)
  • File upload/download
  • WebSocket connections
  • Authentication & authorization
  • Background jobs / queue processing
  • Caching strategies
  • Real network latency

License

MIT

About

Load testing comparison of 8 backend frameworks using k6 - Bun, Go, Rust, Node.js, Hono, Express, Next.js, Laravel

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors