Traffic shaping is a mechanism that helps prevent network congestion by controlling how much traffic enters and leaves a network. By limiting the bandwidth flowing in and out of your network (and load balancer), it's also possible to restrict how much data is transmitted between client and server over a given period of time. This lets you prioritize or deprioritize certain data streams and save resources for mission-critical application services. 

This fundamentally differs from traffic policing, which enables a load balancer to drop traffic outright during extreme activity spikes. Traffic shaping's goal isn't to reduce the number of users accessing a service, but instead focuses on governing how clients access them via performance compromises.

How does traffic shaping work?

Depending on your infrastructure, traffic shaping can occur in a number of ways. A load balancer, for example, might enforce traffic shaping by doing the following: 

  • Regulating client download speeds

  • Regulating client upload speeds

  • Prioritizing one data stream over another

  • Enforcing a limit on the maximum number of bytes traversing the network over a set period of time

  • Reserving bandwidth for demanding or critical application services

  • Delaying HTTP requests and responses once a certain network bandwidth consumption threshold is exceeded

Traffic shaping controls take effect regardless of a client's connection speed. When a client first connects and begins sending traffic, an intermediary (such as a load balancer) will process incoming data according to preset filters or rules, then meter performance accordingly to ensure application health. 

Because of this, traffic shaping is both a performance feature and a high availability feature. Without traffic shaping in place, uncapped bandwidth consumption could leave applications more vulnerable to denial of service (DoS) attacks and other volumetric threats.

What makes traffic shaping useful?

Traffic shaping prevents any one client (or multiple clients at scale) from purposefully or inadvertently degrading application performance. By controlling the flow of data over the network, it's possible to prevent failures. High congestion can cause latency and traffic shaping aims to dramatically reduce latency.

This leads to smoother application performance, better resource management, and positive impacts that end users can perceive.

Does HAProxy support traffic shaping? 

Yes! HAProxy, HAProxy Enterprise, and HAProxy ALOHA include a bandwidth limitation filter to help organizations control traffic flowing through their networks. Using the Filters API, this feature lets you enforce restrictions at the data level (or stream level) while analyzing traffic more closely.

To learn more about traffic shaping in HAProxy, check out our Introduction to Traffic Shaping Using HAProxy blog post or our traffic shaping documentation.