Traffic mirroring stress testing
This topic describes how to use the ALB traffic mirroring feature to simulate production traffic.
Use cases
Many enterprises have stringent requirements for the security and stability of their production workloads. Before you release a new feature or run a stress test, you cannot operate directly in the production environment without affecting the production workload. At the same time, you need real production traffic to verify the correctness of the new feature and evaluate service performance. Manually generated test data often fails to cover the actual distribution of production requests, which results in inaccurate test results.
The traffic mirroring feature of ALB enables production traffic simulation. At the ALB entry point (including the Internet-facing entry point), real client requests destined for the production workload are copied as needed. While the requests are forwarded to the production server group as usual, the copied mirrored traffic is forwarded to the staging server group at the same time. ALB automatically discards the response data returned by the mirrored backend servers and does not affect the normal requests and responses between clients and the production workload. This ensures that test services do not affect the production workload. The main application scenarios are as follows:
-
Use real production traffic to test new features and evaluate service performance. You can complete simulated stress testing without manually generating test data.
-
Simulate production data without generating additional test data, so that test results better reflect real business performance.
-
Reproduce production issues to simplify troubleshooting.
-
Collect and mirror real production traffic from the Internet-facing entry point for traffic replay, simulated stress testing, and capacity evaluation in a staging environment.

Limitations
-
Both Internet-facing ALB and internal-facing ALB support traffic mirroring.
-
Basic Edition ALB instances do not support traffic mirroring.
Prerequisites
-
Create a production server group and a staging server group. The backend protocol for both server groups is set to HTTP. For more information, see Create and manage server groups.
-
Create a listener. For more information, see Add an HTTP listener, add an HTTPS listener, or add a QUIC listener.
Simulate production traffic by using traffic mirroring
Log on to the ALB console.
-
In the top menu bar, select the region of the ALB instance.
-
On the Instances page, click the ID of the target instance.
-
On the Listener tab, find the target listener, and then click View/Modify Forwarding Rule in the Actions column.
-
On the tab, click Add New Rule.
-
In the Add Forwarding Rule section, configure the forwarding conditions to specify the scope of traffic to be mirrored.
Forwarding conditions are used to match the requests to be mirrored. You can match requests as needed based on conditions such as Domain Name and Path. To mirror all production traffic under the listener (for example, to collect all real production requests from the Internet-facing entry point), set the Path to
/*(which matches all paths). To mirror only part of the traffic, set the Path to a specific path. This topic uses an example in which traffic is mirrored to the staging server group if the Path is/test. -
Configure the Action and add the following two actions to the forwarding rule in sequence.
-
Add a Forward to action and select the production server group to ensure that the matched production traffic is forwarded to the production workload as usual, without affecting the production service.
-
Click Add Action, add a Mirror traffic to action, and select the staging server group to copy the matched traffic and mirror it to the staging environment.
ImportantBecause ALB discards response data from the staging server group, you must add a Forward to action for the production server group to this forwarding rule to avoid affecting your production workload.
-
-
Click OK. After the configuration is complete, the production traffic that matches the forwarding rule is mirrored to the staging server group.
Verify the mirroring result
After the configuration is complete, you can use the following methods to confirm that the production traffic is actually collected and mirrored to the staging server group:
-
View the access logs on the staging servers (such as Nginx or Tomcat application logs) to confirm that they receive real requests consistent with the production workload, and that the request content matches the clients' actual access.
-
In the monitoring data of the staging server group, observe that metrics such as the number of requests and connections change with the production traffic, which indicates that the mirrored traffic has successfully reached the staging environment.
-
Confirm that the responses that clients receive when they access the production workload are normal and free of abnormal latency, which verifies that traffic mirroring does not affect the production workload.
If the staging server group does not receive mirrored traffic, check the following items: whether the forwarding conditions can match the actual production requests (for example, whether the path and domain name are correct), whether the priority of the forwarding rule is intercepted by another rule with a higher priority, and whether the backend servers in the staging server group are healthy.