Writing a load test that merely hammers an API endpoint as fast as possible gives you very little actionable data about how your application will behave in production. Realistic load testing requires modelling actual user journeys, injecting diverse test data, adding natural pauses, and choosing the right injection profile to match the traffic pattern you expect. This guide walks through the key practices that separate a useful simulation from one that only floods your server with noise.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gatling/gatling.io-doc/llms.txt
Use this file to discover all available pages before exploring further.
Identify User Journeys Before Writing Code
The foundation of every realistic load test is a clear understanding of how real users interact with your application. Before writing a single line of Gatling code, spend time gathering data from your analytics or APM tools.Product Analytics
Tools such as Amplitude or Firebase reveal which features users actually visit and in what order.
APM Tracing
Datadog, Dynatrace, or similar APM solutions show real request sequences and latency distributions.
Product Owner Input
Subject-matter experts can describe seasonal patterns, power-user workflows, and edge cases analytics may miss.
Network Recording
Use Gatling’s recorder or your browser’s network tab to capture an authentic click-through session.
- User lands on the homepage
- User logs in (authentication)
- User browses products (authenticated homepage)
- User adds a product to the cart
- User checks out
Structuring the Project
A well-organised simulation separates concerns into distinct directories so the codebase remains maintainable as it grows.Defining Endpoints
Endpoints are the atomic HTTP request builders referenced throughout your scenarios.API Endpoint Example — Login
#{username}uses the Gatling Expression Language to pull the value from each virtual user’s session (set by a feeder).- The
.check()step both validates the response (status 200) and extracts the access token for later use.
Web Endpoint Example — Home Page
304 Not Modified is important — real browsers cache resources, so your test should too.
Using Groups for Logical Separation
Groups bundle related requests so that Gatling Enterprise Edition can report on them as a unit (e.g., “Authenticate” or “Checkout”). This makes it far easier to pinpoint which phase of a user journey is slow.The
pause(5, 15) call inserts a random pause between 5 and 15 seconds to simulate the time a real user takes to fill in a form. Skipping think times causes your test to run at an unrealistically high request rate.Building Realistic Scenarios
Flow Control with exitBlockOnFail and randomSwitch
Wrap the entire scenario in exitBlockOnFail so that a virtual user stops as soon as a critical step fails — just as a real user would be unable to proceed after a login error.
Use randomSwitch to distribute virtual users across different flows by percentage, mirroring the real traffic split between user segments.
Injection Profiles
The injection profile controls how virtual users arrive. Choosing the wrong profile can make your results meaningless.- Capacity
- Soak
- Stress
- Breakpoint
- Ramp-Hold
- Smoke
Tests how many users the system can sustain. Increments the arrival rate across multiple levels and checks metrics at each step.
The profiles above use the open workload model — the injector does not cap concurrency. For closed workload models (e.g., a ticketing website with a fixed queue), use
closedModel injection instead.Defining Assertions
Assertions encode your performance requirements into the simulation so that CI/CD pipelines can fail automatically when standards are not met.Dynamic Configuration via System Properties
Avoid hard-coding test parameters. AConfig utility that reads system properties and environment variables lets you change behaviour at run time with no code changes.
Authorization Headers Without Repetition
Rather than setting anAuthorization header on every individual request, wrap the protocol builder with a conditional helper that checks the virtual user’s session for a token.