Skip to content

Instantly share code, notes, and snippets.

@akimabs
Created November 14, 2025 15:26
Show Gist options
  • Select an option

  • Save akimabs/8ed1108015b19e7b06f016505c3cdefa to your computer and use it in GitHub Desktop.

Select an option

Save akimabs/8ed1108015b19e7b06f016505c3cdefa to your computer and use it in GitHub Desktop.

Benchmark: Spring WebFlux vs Spring MVC

Konfigurasi Test

Load Pattern:

  • Ramp up: 15s → 50 users
  • Hold: 30s → 100 users
  • Peak: 15s → 150 users
  • Ramp down: 30s → 0 users
  • Total: ~90 detik per service

Database: PostgreSQL (shared, test sequential untuk menghindari kompetisi resource)

Tool: K6 Load Testing


Hasil Benchmark

🟢 Spring WebFlux

Metric Value
Throughput 9,415 req/s
Total Requests 847,365
Error Rate 0.00%
Avg Latency 7.46ms
Median (p50) 7.25ms
p90 12.9ms
p95 14.05ms
Max 93.1ms

Detail:

http_req_duration: avg=7.46ms  min=444µs  med=7.25ms  max=93.1ms
  - Waiting:   7.44ms
  - Receiving: 12.51µs
  - Sending:   4.17µs
  - Blocked:   941ns

🔵 Spring MVC

Metric Value
Throughput 5,144 req/s
Total Requests 462,981
Error Rate 0.00%
Avg Latency 13.69ms
Median (p50) 11.99ms
p90 26.28ms
p95 32.42ms
Max 289.5ms

Detail:

http_req_duration: avg=13.69ms  min=510µs  med=11.99ms  max=289.5ms
  - Waiting:   13.63ms
  - Receiving: 49.04µs
  - Sending:   5.82µs
  - Blocked:   3.08µs

Perbandingan

Metric WebFlux Spring MVC Selisih
Throughput 9,415 req/s 5,144 req/s +83%
Avg Latency 7.46ms 13.69ms -45%
p50 7.25ms 11.99ms -40%
p90 12.9ms 26.28ms -51%
p95 14.05ms 32.42ms -57%
Max 93.1ms 289.5ms -68%
Total Requests 847,365 462,981 +83%
Error Rate 0.00% 0.00% sama

Visualisasi:

Throughput (req/s)
━━━━━━━━━━━━━━━━━━━━
WebFlux  ████████████████████ 9,415
MVC      ███████████           5,144

Latency p95 (ms)
━━━━━━━━━━━━━━━━━━━━
WebFlux  ████                  14.05
MVC      ██████████            32.42

Tech Stack

Spring WebFlux (Port 8080)

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>4.0.0-SNAPSHOT</version>
</parent>

<properties>
    <java.version>25</java.version>
</properties>

<dependencies>
    <!-- Reactive Web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    
    <!-- Reactive Database -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-r2dbc</artifactId>
    </dependency>
    
    <!-- PostgreSQL R2DBC Driver -->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>r2dbc-postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

Spring MVC (Port 8081)

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>4.0.0-SNAPSHOT</version>
</parent>

<properties>
    <java.version>25</java.version>
</properties>

<dependencies>
    <!-- Traditional Web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    
    <!-- Traditional Database -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    
    <!-- PostgreSQL JDBC Driver -->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

Kesimpulan

Pemenang: Spring WebFlux

  • 83% lebih cepat dalam throughput
  • 45-57% lebih rendah dalam latency (semua percentile)
  • Lebih stabil di bawah tekanan (max latency 3x lebih baik)
  • Cocok untuk high concurrency (100+ concurrent users)

Spring MVC tetap viable untuk:

  • Aplikasi sederhana dengan concurrency rendah
  • Tim yang belum familiar dengan reactive programming
  • Aplikasi dengan blocking library yang tidak punya reactive driver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment