Skip to main content

Introduction

DataStream is a real-time CDC (Change Data Capture) pipeline that delivers database changes to clients using multiple protocols: REST API, WebSocket, SSE (Server-Sent Events), WebTransport, and NATS WebSocket (direct broker connection).

Built with Hexagonal Architecture in Go, it provides sub-100ms latency from database INSERT to client notification.

Why Data Stream?

Traditional approaches to real-time data synchronization often involve:

  • Polling databases (high latency, wasteful)
  • Custom pub/sub implementations (complex to maintain)
  • Vendor lock-in solutions (expensive, inflexible)

Data Stream solves these problems by:

  • CDC-based: Captures database changes at the source (PostgreSQL WAL)
  • Protocol agnostic: Supports REST API, WebSocket, SSE, and WebTransport
  • Decoupled: Read model (Redis) separated from write model (PostgreSQL)
  • Observable: Built-in metrics, logging, and tracing
  • Production-ready: Deployed on Fly.io with automatic scaling

Architecture Overview

Architecture Overview

Key Features

Multi-Protocol Support

ProtocolLatencyDirectionBest For
WebTransport0.5-2msBidirectionalUltra-low latency, QUIC/HTTP3
NATS WebSocket0.5-2msBidirectionalDirect broker, wildcards
WebSocket1-5msBidirectionalInteractive apps, gaming
SSE10-50msServer → ClientDashboards, feeds
REST API50-200msRequest/ResponseHistory, latest data, polling

Hexagonal Architecture

Clean separation of concerns:

  • Domain: Pure business logic, no external dependencies
  • Ports: Interface definitions (contracts)
  • Adapters: External integrations (Redis, NATS, HTTP)

CDC Pipeline

Real-time data capture without polling:

  1. PostgreSQL writes to WAL (Write-Ahead Log)
  2. Debezium captures changes and publishes to NATS
  3. Go consumer processes and publishes to Redis
  4. Backend streams to connected clients

Technology Stack

ComponentTechnologyPurpose
DatabasePostgreSQL 16Source of truth
CDCDebezium 2.5Change capture
Message BrokerNATS JetStreamEvent streaming
CacheRedis 7Read model + Pub/Sub
BackendGo + FiberAPI + Streaming
DeploymentFly.ioGlobal edge deployment

Live Demo

Try it now!

All clients are running live at https://datastream.andrebassi.com.br

Interactive Clients

ClientDescriptionTry Online
DashboardOverview of all protocolsOpen Dashboard
WebSocketReal-time bidirectionalOpen Client
SSEServer-Sent EventsOpen Client
NATSDirect broker connectionOpen Client
WebTransportQUIC/HTTP3 streamingOpen Client
REST APIHTTP pollingOpen Client
ComparisonSide-by-side protocolsOpen Client

API Endpoints

Streaming Endpoints

  • WebSocket: wss://datastream.andrebassi.com.br/ws/crash
  • SSE: https://datastream.andrebassi.com.br/sse/crash
  • WebTransport: https://datastream.andrebassi.com.br:4433/wt
  • NATS WebSocket: ws://localhost:8443 (local only)