# Performance Profiling and Load Testing

> Find real bottlenecks with profilers and load tests instead of guessing, then fix the part that matters. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/performance-profiling
Last updated: 2026-11-28

Find real bottlenecks with profilers and load tests instead of guessing, then fix the part that matters.

Advanced · about 5 hours · difficulty 3/5

Learn first: [Metrics, Dashboards and Alerting](https://www.internhack.in/roadmaps/tracks/backend/metrics-alerting), [Indexes and Query Performance](https://www.internhack.in/roadmaps/tracks/backend/indexes-query-performance)

Performance work without measurement is guesswork. The discipline is: **measure, find the bottleneck, fix it, measure again**.

### Load testing

Tools like **k6**, Locust, Gatling, JMeter or autocannon simulate many users hitting your API.

- Define a realistic scenario (login, browse, checkout) and targets (for example p95 under 300 ms at 200 requests per second).
- Ramp load up gradually to find the **knee**, where latency starts climbing sharply.
- Run against a production-like environment with realistic data volumes; an empty database lies.
- Watch server metrics during the test to see which resource saturates first: CPU, DB connections, memory or an external API.

### Profiling

A **profiler** shows where CPU time or memory goes inside your process:

- **CPU profiles** and **flame graphs**: the widest bars are where time is spent. Node has `--cpu-prof` and Clinic.js, Python has cProfile and py-spy, Go has pprof, Java has JFR and async-profiler.
- **Heap snapshots** and allocation profiles find memory leaks: objects that keep growing between snapshots.
- **Continuous profiling** in production (Pyroscope, Parca, cloud profilers) catches issues that only appear under real traffic.

### The usual suspects

In most backends the bottleneck is not your language but I/O: N+1 queries, missing indexes, chatty calls to other services, large JSON serialization, synchronous CPU work blocking an event loop, or no caching. Fix these before micro-optimizing loops.

### Pitfalls

- Optimizing code that accounts for 1 percent of the time.
- Load testing from a laptop that becomes the bottleneck itself.

You are ready to move on when you can load test an endpoint, find its bottleneck with a flame graph or query plan, fix it and show the before and after numbers.

## Key concepts

- **Load testing with k6 or Locust**
- **Finding the saturation point**
- **CPU profiles and flame graphs**
- **Heap snapshots and memory leaks**
- **Event loop blocking**: Critical for Node.js
- **Continuous profiling**
- **Benchmarking methodology**

## Mini project

Write a k6 script for your three busiest endpoints, find the first bottleneck, fix it using a profile or query plan, and publish a short before/after report with p95 and throughput.

## Check yourself

Your p95 latency doubles under load while CPU stays at 30 percent. What are the likely bottlenecks?

## Free resources

- [Grafana k6 documentation](https://grafana.com/docs/k6/latest/) (Grafana Labs)
- [Flame Graphs](https://www.brendangregg.com/flamegraphs.html) (Brendan Gregg)
- [Profiling Node.js applications](https://nodejs.org/en/learn/getting-started/profiling) (Node.js)

Previous: [Distributed Tracing with OpenTelemetry](https://www.internhack.in/roadmaps/tracks/backend/distributed-tracing-otel) · Next: [Vertical and Horizontal Scaling](https://www.internhack.in/roadmaps/tracks/backend/scaling-strategies)

## More in Observability and Performance

- [Structured Logging](https://www.internhack.in/roadmaps/tracks/backend/structured-logging)
- [Metrics, Dashboards and Alerting](https://www.internhack.in/roadmaps/tracks/backend/metrics-alerting)
- [Distributed Tracing with OpenTelemetry](https://www.internhack.in/roadmaps/tracks/backend/distributed-tracing-otel)
- [Performance Profiling and Load Testing](https://www.internhack.in/roadmaps/tracks/backend/performance-profiling)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
