Skip to main content
Back to Projects

Lighter Liquidations

All Systems Operational

Backend service for Lighter.xyz that ingests perpetuals liquidation events over WebSockets, deduplicates noisy replay batches, aggregates notional USD into per-minute buckets in Upstash Redis, and serves a rolling 24 hour liquidation total over HTTP.

Tech stack

Node.jsWebSockets (Lighter streams)Upstash RedisMinute-bucket time seriesHTTP REST API

Overview

Lighter Liquidations is a real-time data pipeline that tracks liquidation activity across Lighter.xyz markets and maintains a rolling 24-hour liquidation metric. The system is designed to handle noisy WebSocket streams, eliminate duplicate events, and aggregate high-frequency data into a query-efficient time series. It follows a split architecture: a persistent worker ingests and processes streaming data, while a stateless HTTP API serves pre-aggregated results. Redis acts as the aggregation layer using minute-level buckets with TTL-based retention.

What it does

  • Consumes liquidation events from Lighter WebSocket streams in real time
  • Deduplicates repeated or batched events to prevent inflated metrics
  • Aggregates liquidation volume into minute-level time buckets
  • Maintains a rolling 24-hour liquidation total using Redis TTL
  • Exposes a lightweight HTTP API for dashboards and integrations

Technical breakdown

System architecture

The system is split into two independent processes: a long-running worker and a stateless HTTP server. The worker maintains WebSocket connections, processes incoming liquidation events, and updates Redis in real time. The API server reads aggregated data from Redis and exposes it via REST endpoints.

Ingestion and data layer

WebSocket ingestion is handled using Node.js with persistent connections and reconnection logic. Redis (Upstash REST) is used as a time-series store where each minute acts as a bucket. Deduplication logic ensures idempotent aggregation by filtering repeated events within batch windows. The rolling 24-hour metric is computed dynamically by summing active buckets.

Technical challenges

Deduplication of noisy WebSocket streams

Lighter streams often send repeated or batched liquidation events, which can lead to overcounting. A deduplication strategy was implemented by comparing key fields within short time windows, ensuring idempotent aggregation without dropping legitimate events.

Designing a rolling time window

Instead of storing a single aggregate value, liquidation data is stored in minute-level buckets with a 25-hour TTL. This allows efficient computation of a rolling 24-hour metric while keeping memory usage bounded and predictable.

Separation of ingestion and serving layers

Running WebSocket ingestion and API serving in the same process created stability issues. Splitting them into worker and server processes ensured better fault isolation and allowed independent scaling and restarts.

Handling WebSocket reliability

Frequent disconnects and network instability required implementing reconnection logic and ensuring no data corruption during reconnect cycles. The system prioritizes consistency over completeness, avoiding incorrect spikes in metrics.

Who it is for

Built for analytics platforms, trading dashboards, and developers who need accurate real-time liquidation data from Lighter.xyz without handling raw WebSocket streams or dealing with duplicate event noise.

Challenges

  • Deduplicating noisy WebSocket liquidation events
  • Handling reconnects without corrupting aggregates
  • Designing efficient rolling 24h time window
  • Choosing optimal bucket granularity (per-minute)
  • Syncing worker and API without race conditions
  • Avoiding spikes from replayed event batches

Learnings

  • Idempotency is critical in streaming systems
  • Bucketed time-series > single aggregate values
  • Separate ingestion and serving layers
  • Consistency matters more than completeness
  • Redis works well for short-term time-series
  • Always design for failure scenarios

Related Projects

LighterPulse

LighterPulse

Analytics and exploration platform for the Lighter.xyz ecosystem, covering dashboards, a block explorer, exchange statistics, multi-venue funding comparison, and protocol announcements. Redis-backed caching and a split between live and cached data paths keep the UI responsive.

All Systems Operational
View Details
WalletX

WalletX

Full-stack FinTech-style wallet demo: P2P transfers, balances, history, and dashboard analytics. MongoDB multi-document transactions enforce ACID semantics so debits and credits stay consistent under concurrency (simulated funds, not real money).

All Systems Operational
View Details
View All Projects