Back to Projects

Stark — Real-Time Typing Indicator Service

Java
Spring Boot
WebSocket
Redis Pub/Sub
ConcurrentHashMap

How do you broadcast an ephemeral real-time signal across multiple servers that have no knowledge of each other, without central coordination?

What I Built

A distributed typing indicator service — the “Alice is typing...” signal seen in WhatsApp, Slack, and Discord. The challenge is not just emitting events; it is preserving real-time behavior in a horizontally scaled environment without topology configuration.

Key Engineering Decisions

  • Redis Pub/Sub broadcast (instead of direct routing): Servers can scale with zero config; each node checks locally if it owns the recipient session.
  • In-memory sessions (ConcurrentHashMap): Ultra-fast local lookups with no extra network hop on the hot path.
  • isTyping state guard: Rapid typing bursts are collapsed, so recipients receive a clean signal instead of event spam.
  • ScheduledExecutorService with cancel-and-reschedule: Timer resets on every typing event and clears exactly 2 seconds after last activity.
  • WebSocket over HTTP polling: Persistent bidirectional connectivity for significantly lower latency and reduced bandwidth.

Architecture Choice I’m Most Proud Of

I intentionally chose broadcast over direct routing. A centralized registry for user-to-server mapping adds locking, stale-state cleanup, and crash recovery complexity. Broadcast is self-healing, supports multi-device delivery naturally, and scales with near-zero operational overhead.

The trade-off is minor redundant processing on nodes without the recipient — a worthwhile cost for simpler and more robust distributed behavior.

View on GitHub