2 — GlobalChat Realtime Messaging Service
Rank 2 of 28 · Tier S · app/GlobalChatService
Stack: Go 1.25, Cassandra 4.1.3 (gocql + gocqlx), Redis, Kafka (IBM/sarama), gorilla/websocket, chi, Prometheus, APNs, AWS S3
Status: Deployed under systemd on the origin host. Schema migrates on boot. Runbook written.
Why this ranks here. It is the other half of the systems-design canon: a stateful realtime service. Connection lifecycle, presence, ordering, delivery, backpressure, fan-out, and a storage layer whose partition design you have to defend. 26K lines of Go with 29 test files including benchmarks and dedicated race tests.
What it is
A single Go service carrying every messaging surface of a multi-mode consumer platform: 1:1 chat, groups, communities, channels, presence, typing, reactions, edits/deletes, view-once media, live location, voice transcription, link previews, push, and WebRTC call signaling.
Architecture
Clients (iOS · Web · Android)
│ wss://…/ws HTTPS
▼ ▼
WSSServer (gorilla/websocket) HTTPServer (chi + CORS)
│ │
└──────────────┬─────────────────────┘
▼
event_router · session_manager
│
┌────────────┼───────────────┬──────────────┐
▼ ▼ ▼ ▼
Cassandra Redis Kafka S3
(messages, (presence, (push consumer, (media)
history) sessions) cross-service)
│
▼
APNs / push sender
The engineering that matters
Connection and session layer
wss.go, session_manager.go, presence.go — connection registry, presence
TTL, session adoption. The WebSocket hub is benchmarked (wss_bench_test.go)
and batch-tested (wss_batch_test.go), not just unit-tested.
Storage layer
cass.go builds the Cassandra session with TLS and x509 trust, wrapped in
gocqlx. Conversation identity is its own module (conversationid.go) with
its own test — because a conversation id that is derived inconsistently across
services silently splits a chat in half.
Contract discipline
api/openapi.yaml + api/asyncapi.yaml with shared component schemas, and an
asyncapi_coverage_test.go that fails the build when the implementation
and the async contract drift. That test is the artifact to point at when a bank
asks how you keep services honest.
Concurrency correctness
Named, dedicated tests: calling_race_test.go, typing_test.go,
edit_delete_test.go, integration_loop_test.go,
integration_cassandra_test.go. Race conditions in this service were treated
as first-class defects with reproductions, not as flakes.
Observability
metrics.go + metrics_render_test.go + pprof.go. Prometheus surface, and a
test that the rendering itself is correct.
Scope
| Metric | Value |
|---|---|
| Go source | 26,176 lines, 77 files |
| Test files | 29, including benchmarks and race tests |
| Feature modules | ~40 (service/*.go) |
| Datastores | Cassandra, Redis, Kafka, S3 |
| Contracts | OpenAPI + AsyncAPI, CI-checked for coverage |
| Deployment | systemd unit + docker-compose local bring-up + RUNBOOK.md |
Interview surface this opens
- WebSocket connection lifecycle at scale: heartbeats, half-open detection, reconnection with resume
- Presence: TTL vs heartbeat vs Redis keyspace notifications, and the cost of each
- Message ordering and idempotency across reconnects
- Cassandra partition design for chat history — the classic "wide partition" trap
- Fan-out to N devices per user, and push as the fallback path
- Backpressure: what happens when a slow client cannot drain its channel