We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Messaging Event Systems
Free preview: the first 2 parts of this 7-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Messaging Event Systems
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
A content-based router has fixed rules: "international orders go here, domestic orders go there." If you need to add a new destination, say, a new warehouse in Canada, you redeploy the router code.
A dynamic router adapts its routing rules at runtime, without redeployment. New participants register themselves with the router. Routing tables update automatically. Routes change based on load, availability, or configuration changes.
Think of a GPS navigation system. It doesn't have hardcoded routes. It discovers road conditions in real time and adjusts. New roads are added to the map. Closed roads are removed. Traffic patterns shift the optimal route. The GPS dynamically computes the best path every time.
Dynamic routing is where content-based routing meets runtime configuration. It's the pattern that makes these real-world systems possible:
The dynamic router maintains a routing table that can be updated at runtime:
class DynamicRouter {
private routingTable: Map<string, string> = new Map();
// Services register themselves
registerRoute(messageType: string, destination: string) {
this.routingTable.set(messageType, destination);
}
// Services deregister when shutting down
removeRoute(messageType: string) {
this.routingTable.delete(messageType);
}
route(message: Message): string {
const destination = this.routingTable.get(message.type);
if (!destination) throw new Error(`No route for: ${message.type}`);
return destination;
}
}
Dynamic rule sources:
| Source | How It Works | Use Case | Update |
|---|---|---|---|
| Service registry (Consul, etcd) | Services register on startup, deregister on shutdown | discovery | 1-5 seconds |
| Configuration store (database) | Admin updates routing rules via API or UI | Tenant routing, feature flags | Seconds to minutes |
| Control messages | Special messages on a dedicated channel update the routing table | Self-organizing systems | Milliseconds |
| Load metrics | Route based on current queue depth or service latency | Load balancing | Real-time |
Real-world example: A multi-tenant SaaS platform routes messages by tenant ID. New tenants are provisioned with their own processing queue. The dynamic router reads the tenant-to-queue mapping from a configuration store. When a new tenant signs up, the provisioning service adds a routing entry, no router redeployment needed.
HashiCorp Consul's key-value store is a popular backing store for dynamic routing tables. The router watches a key prefix (e.g., routing/tenants/) and reloads its in-memory table whenever a key changes. Consul's blocking queries provide near-real-time notification of changes without polling.