Patterns for Building Realtime Features
Realtime features in apps enhance collaboration by sharing user-triggered changes instantly. Key patterns include:
- Poke/Pull: Server notifies clients (poke) to fetch new data (pull). Easy integration but causes simultaneous requests (fan-out), which can be mitigated with caching.
-
Push State: Server sends entire updated state immediately. Reduces fan-out but can overwhelm clients with data and doesn't scale well for large states.
-
Push Ops: Server sends specific operations instead of full state, enabling clients to update efficiently. Requires initial state fetching.
-
Event Sourcing: Server sends events instead of state, requiring client-side logic to apply changes. Promotes reusable business logic but adds complexity.
-
Transports: Options include websockets, SSE, and polling. Challenges arise in horizontally scaled systems regarding server-client coordination, solvable via Pub/Sub infrastructures.