EnSync Engine Documentation Help

SUB Command Overview

Purpose

The SUB command is a cornerstone of EnSync's event distribution system, enabling services to register interest in specific event types and receive real-time updates. This command implements the subscriber side of the publish-subscribe pattern, allowing for dynamic, scalable event-driven architectures.

Key Capabilities

Dynamic Subscription

Services can subscribe to specific event types at runtime, allowing for flexible system configurations without code changes. This dynamic nature enables systems to adapt to changing requirements and traffic patterns.

Competing Consumer Pattern

Multiple instances of the same service can subscribe using the same access key, implementing the competing consumer pattern. This pattern ensures that events are processed exactly once by one of the available service instances, enabling horizontal scaling.

Hierarchical Event Filtering

The SUB command supports hierarchical event filtering using path-like event names (e.g., domain/resource/action). Subscribers can use wildcards to receive all events within a specific domain or of a specific action type.

Position Tracking

The system maintains precise tracking of each client's position within each event stream, enabling reliable resume capabilities after disconnections or service restarts.

Technical Implementation

The SUB command works by:

  1. Authenticating the subscriber using their client ID

  2. Verifying that the subscriber has permission to receive the specified event type

  3. Registering the subscription in the client registry

  4. Loading initial events based on the client's last position

  5. Delivering events in real-time as they become available

This implementation ensures that subscribers receive all events they are authorized to access, without gaps or duplicates, even across disconnections.

Integration Points

The SUB command integrates with:

  • Authentication System: Verifies subscriber identity and permissions

  • Client Registry: Tracks active subscriptions and client state

  • Position Tracking System: Maintains client position within event streams

  • Event Storage: Retrieves historical and new events for delivery

  • Competing Consumer System: Ensures events are delivered to exactly one instance

Use Cases

  • Building reactive microservices that respond to system events

  • Creating real-time dashboards and monitoring applications

  • Implementing event-driven workflows across distributed systems

  • Developing collaborative applications with live updates

  • Building notification systems that respond to specific triggers

  • Implementing CQRS (Command Query Responsibility Segregation) patterns

  • PUB: Publishes events that subscribers receive

  • UNSUB: Cancels subscriptions created with SUB

  • PAUSE: Temporarily halts delivery of events from a subscription

  • CONTINUE: Resumes delivery of events after a PAUSE

Last modified: 07 October 2025