An Azure service that delivers high availability and network performance to applications.
Azure Load Balancer alone cannot meet the cookie-based affinity requirement because it is a Layer 4 (TCP/UDP) load balancer and does not support cookie-based session affinity. Cookie affinity requires a Layer 7 (HTTP/HTTPS) load balancer that can inspect and set cookies.
To satisfy all requirements (VM-based app, multiple instances per VM on different ports, and cookie-based affinity), use Azure Application Gateway in front of the VMs and configure:
- Application Gateway as a Layer 7 load balancer with cookie-based session affinity enabled in the HTTP settings.
- Backend pool containing the VMs.
- HTTP settings that:
- Enable Cookie based affinity.
- Forward traffic to the appropriate backend ports (9000 and/or 9001). This can be done with:
- Separate HTTP settings per port (one for 9000, one for 9001) and corresponding routing rules, or
- Path-/host-based routing if the application can distinguish instances that way.
Application Gateway supports:
- Layer 7 routing and cookie-based session affinity.
- Round-robin distribution across backend instances.
- Hosting multiple “sites” or routes behind a single gateway, which can be mapped to different ports on the same VM.
If the application absolutely requires TCP-level access without HTTP/TLS termination, Azure Load Balancer can be used, but then cookie-based affinity is not possible. In that case, either remove the cookie requirement or use a different affinity mechanism (for example, X-Forwarded-For–based stickiness behind a Layer 7 proxy as described for Entra Application Proxy scenarios).
In summary, the Azure-native way to meet all listed requirements is to front the VM-based application with Azure Application Gateway, configure backend HTTP settings per port, and enable cookie-based session affinity.
References: