Distributed Systems
WebSockets
Node Topology
Network Health
Circle Topology

Circle topology of Nodes for distributed system with WebSockets - How to mark all Nodes when topology healthy?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

In the realm of distributed computing, the circle topology represents a unique and effective approach for organizing nodes in a network. Especially when integrated with contemporary technologies such as WebSockets, circle topology can offer robust scalability and fault tolerance. This article delves deeply into how to maintain a healthy circle topology in a distributed system employing WebSockets, including methods to constantly verify and confirm the health of all nodes.

Understanding Circle Topology

Circle topology, also known as ring topology, is a network configuration where each node is connected to exactly two other nodes, forming a circular data path. In a typical circle topology, every message sent within the network travels through each node in the ring until it reaches its destination. This topology is favored in scenarios where systems require an orderly and predictable network path.

Integration with WebSockets

WebSockets provide a full-duplex communication channel over a single, long-lived connection, which is ideal for real-time and interactive applications. When WebSockets are applied in a circle topology, each node can maintain an open and continuous connection with its neighbors. This feature ensures realtime data transmission and immediate state update which is crucial for maintaining the health of the network.

Monitoring and Marking Health of Nodes

Ensuring each node in a circle topology is healthy is vital for the overall functionality of the system. Here's a typical process on how to mark all nodes as healthy in a WebSocket-enabled circle topology:

1. Continuous Health Checks

Each node in the network periodically sends health check messages to its adjacent nodes via its open WebSocket connections. These messages might contain data like CPU usage, memory usage, and network latency.

2. Acknowledgment Responses

Upon receiving a health check message, a node responds back with an acknowledgment. This acknowledgment can include the health status of the responding node itself.

3. Marking the Nodes

Based on the responses from the adjacent nodes, each node can mark itself and its neighbors as healthy or unhealthy in its local data store. This marking can be a simple flag associated with each node.

4. Error Handling and Fault Tolerant Mechanisms

If a node fails to receive an acknowledgment from a neighbor within a predetermined time frame, it marks the neighbor as unhealthy. Depending on the application’s criticality, various strategies like rerouting the message, attempting reconnection, or even initiating a node replacement can be implemented.

Scalability and Limitations

One significant advantage of using circle topology with WebSockets in distributed systems is the minimization of bottlenecks that can occur with central server models. However, the topology does face limitations, particularly in terms of scalability. As the number of nodes increases, the time it takes for a message to pass all nodes in the ring increases.

Example Implementation

Here is a simple pseudo-code to illustrate node monitoring in a circle topology:

javascript
1function healthCheck() {
2  sendHealthCheckMessage(nextNode);
3  waitForResponse();
4}
5
6function sendHealthCheckMessage(node) {
7  const message = { type: 'HealthCheck', from: currentNode, payload: {...}};
8  node.websocket.send(JSON.stringify(message));
9}
10
11function waitForResponse() {
12  node.websocket.on('message', function incoming(data) {
13    let response = JSON.parse(data);
14    if(response.type === 'HealthCheckAck' && response.payload.status === 'healthy') {
15      markNodeAsHealthy(response.from);
16    } else {
17      markNodeAsUnhealthy(response.from);
18    }
19  });
20}

Summary Table

FeatureDetails
Topology TypeCircle/Ring
Communication ProtocolWebSockets
Node Health CheckPeriodic messages & responses
Fault ToleranceError handling via rerouting or node replacements
ScalabilityLow latency for small networks, increases with size

Conclusion

Circle topology in distributed systems, combined with WebSockets, provides a structured and efficient way to maintain network health and integrity. While the architecture possesses inherent scalability challenges, its capacity for real-time communication and built-in fault tolerance makes it a valuable model for certain types of network applications.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design