How Load Balancers Route
How Load Balancers Route Traffic Based on Request
1. Problem Statement
Imagine this setup:
A user opens your website
Another user calls your API
Someone else loads images
But your load balancer sends everything to the same backend server.
What happens?
API requests slow down image delivery
Static content consumes application resources
Backend becomes overloaded and inefficient
Even worse:
Everything looks βUPββ¦ but performance is inconsistent.
π The problem is simple: Not all traffic is the same β but itβs being treated the same.
2. Concept Explanation
What is Content Switching?
Content Switching is a technique where a load balancer:
π Makes routing decisions based on the request itself
Instead of blindly forwarding traffic, it inspects the request and decides:
Where should this go?
Which backend is best suited?
Simple Analogy
Think of a sorting system at a courier facility:
Packages arrive at one entry point
Labels are checked
Items are routed to different destinations
Similarly:
/api β API servers
/images β image servers
/app β web servers
π The load balancer becomes intelligent, not just a traffic distributor.
3. Types / Variations
1. URL Path-Based Routing (Most Common)
/api/* β API backend
/images/* β image server
/app/* β web server
π Simple and widely used in real-world deployments
2. Host-Based Routing (High-Level)
api.example.com β API servers
www.example.com β web servers
π Useful for multi-domain architectures
3. Header-Based Routing (Brief)
Based on:
User-Agent
Custom headers
Cookies
π Used in advanced scenarios (A/B testing, version routing)
4. How It Works Internally
Letβs break it down step by step:
Client sends request
- Example: GET /api/users
Load Balancer receives request
Load Balancer inspects:
URL path
Host header
Other attributes
Policy is evaluated
- Match: /api/*
Decision is made
- Route to API backend
Request is forwarded to correct server
π This happens in milliseconds, for every request.
5. Diagram
Flow:
Client β Load Balancer β
/api β API Server
/images β Image Server
/app β Web Server
6. Real-World Example
Scenario: Single Domain, Multiple Services
Your application:
example.com/app β Web UI
example.com/api β Backend APIs
example.com/images β Static content
Instead of:
β One backend handling everything
You design:
β Separate backends optimized for each workload
Microservices Architecture
Modern apps follow this pattern:
API services scale independently
Static content served via optimized nodes
Frontend handled separately
π Content switching enables clean architecture + better performance
7. Common Issues / Pitfalls
1. Incorrect Routing Rules
Wrong match condition
Traffic goes to wrong backend
π Result: broken application behavior
2. Overlapping Policies
Example:
/api/*
/api/v1/*
π Which one should match first?
π Order matters β always.
3. Performance Overhead
Every request is inspected
Complex rules = more processing
π Keep policies simple and efficient
8. Try It Yourself (MANDATORY)
Try it yourself π
π Open Full Visualizer (Visualizer Link)
9. Key Takeaways
Not all traffic is equal
Load balancers can make intelligent decisions
Content switching improves performance and scalability
Proper rule design is critical
Itβs the foundation for modern architectures
10. Conclusion
Content Switching transforms a load balancer from:
π A simple traffic distributor to π An intelligent traffic router
It allows you to:
Separate workloads
Improve performance
Design scalable systems
And most importantly:
π Build architecture that matches real-world traffic behavior
11. Series Continuity
Previously: π SSL Termination β how encryption is handled efficiently
Next: π Responder & Rewrite Policies β modifying traffic on the fly
12. Final Thought
A good load balancer distributes traffic. A great load balancer understands traffic.
π Content Switching is where that intelligence begins.
13. Practical: NetScaler Hands-on
13.1 Mini Lab
Create 3 backend services:
Web server
API server
Image server
Configure Content Switching vServer
Route based on URL path
13.2 Variation / Experiment
Add rule: /test β new backend
Break a rule intentionally
Observe incorrect routing
π This is how you truly learn behavior
13.3 Commands (3β5 max)
add cs vserver cs_vsrv HTTP 10.0.0.10 80
add cs policy api_policy "HTTP.REQ.URL.STARTSWITH(\"/api\")" api_lb_vsrv
add cs policy img_policy "HTTP.REQ.URL.STARTSWITH(\"/images\")" img_lb_vsrv
bind cs vserver cs_vsrv -policyName api_policy -priority 10
bind cs vserver cs_vsrv -policyName img_policy -priority 20





