How mtgnorton/ws-cluster works
Main Components
• Client Layer: WebSocket clients connecting to the service via endpoints such as /ws/connect.
• API Gateway / Router: Supporting HTTP endpoints for actions like push (/ws/push) or handshake/initiation.
• WebSocket Server: The core server handling WS connections (e.g., components in the “ws” and “http/server” directories).
• Message Queue System: The message dispatch system (using Redis and Kafka implementations found under core/queue, along with separate handlers for different message types).
• Core Business Logic/Manager: Modules like core/manager, core/client, and core/checking that encapsulate connection management, validations, and operations.
• Shared Utilities: Common libraries implemented in shared/ (auth, jwtws, kit, and utils) that support token authentication, JWT, common algorithms, and other helper functions.
• Monitoring & Profiling: pprof integrated with the HTTP server plus tools for Prometheus and Grafana configuration (check directories tools/wspprof, tools/wsprometheus, and k8s/prometheus) to capture performance and metric data.
• External Services & Deployment: Kubernetes deployment manifests (in k8s/), Dockerfiles for containerization, and continuous integration (Jenkins) pointers from the README hinting at build and deployment automation.
Out Relationships and Interactions
• It then shows how business systems call the push API to send data, which is enqueued within the message queue (with separate implementations for Redis and Kafka) located in the “core/queue” directory.
• Supporting modules such as error logging (logger), and shared libraries that provide helper functions seamlessly used across the codebase.
Architectural Patterns and Design Principles
• The system follows a modular design with clear separation of concerns: networking (ws, http), business logic (core), message queuing (queue), and shared utilities.
• It incorporates a microservices style or component-based architecture with components loosely coupled; especially evident by separating concerns (e.g., connection handlers in “ws/handler” vs. API endpoints in “http/server”).
• Use of dependency injection and configuration management (through the “config” and “conf” directories) to provide environment-specific settings.
Relevant Technologies, Frameworks, and Libraries
• Go language as the primary implementation language.
• Docker (evidenced by Dockerfile) for containerization.
• Kubernetes and Istio (from k8s/ files) for orchestration and intelligent load balancing.
• Redis and Kafka (core/queue/queue_redis.go, core/queue/kafka) for message queuing.
• pprof, Prometheus, and Grafana for performance analysis and monitoring.
• Swagger for API documentation (tools/swagger and docs/ directory).
• Jenkins for automated builds as noted in the README.
• Error logging via Sentry integration (tools/wssentry).
Recommended Detail Level
• To detail each subsystem and inter-connection, as this project uses multiple layers and external services.
• Load-balancing and clustering behaviors explicitly (e.g., mention how Istio and Kubernetes facilitate connection routing based on active sessions).