What is event-driven REST and when do you use webhooks vs SSE vs WebSockets?
Answer
Three push mechanisms serve different needs. Webhooks: the server POSTs to a client-registered URL when events occur. Best for: event notifications where the client does not need to be actively connected, server-to-server integrations (Stripe, GitHub, Shopify). Drawbacks: clients must expose a public endpoint, and delivery failures need retry logic. Server-Sent Events (SSE): the server streams newline-delimited JSON events over a long-lived HTTP connection (Content-Type: text/event-stream). Best for: one-way server-to-browser push (live feeds, progress bars, notifications). SSE works over standard HTTP/1.1, is automatically reconnecting, and is natively supported by browsers via EventSource. Drawback: HTTP/1.1 limits to 6 connections per domain. WebSockets: full-duplex bidirectional communication over a persistent TCP connection. Best for: real-time collaborative applications (live chat, multiplayer games, collaborative editing) where both client and server need to send messages. Drawback: more complex infrastructure (requires WebSocket-aware load balancers and sticky sessions or pub/sub backend).
Previous
What are backward compatibility strategies and Postel's Law in REST API evolution?
Next
How do you optimize REST API performance — N+1 avoidance, sparse fieldsets, and response compression?
More REST API Design Questions
View all →- Advanced What is the Richardson Maturity Model and what are its four levels?
- Advanced How do you decide between REST, GraphQL, and gRPC for a new API?
- Advanced What is consumer-driven contract testing with Pact?
- Advanced What are backward compatibility strategies and Postel's Law in REST API evolution?
- Advanced How do you optimize REST API performance — N+1 avoidance, sparse fieldsets, and response compression?