Pull vs. Push Architectures
In a push architecture the service that owns an event sends it to everyone interested, and in a pull architecture the users query the service for it.
Cristiano Ronaldo uploads an image on Instagram. Sending it to millions of followers in one shot overloads the server. The followers are of three types: big fans who want the notification immediately, 1 million Indian followers who want the image without a notification, and 10 million passive followers.
- Push, for the big fans. The notification service broadcasts on upload. Ten batches, six minutes apart, lower the peak load and reach every big fan in one hour.
- Pull, for the followers. They open the app at random times and query the notification service, so the load is much less spiky.
- Hybrid. The notification service pushes events to a message queue, which decouples the ingestion rate from the exit rate.
Push has very low latency and leaves no stale notifications. Pull has lesser peak load, but a notification stays in the cache for 24 or 48 hours.
Consistency vs. Availability
Consistency versus availability is the trade-off between returning the latest data and returning a response at all.
A consistent system gives the latest data in its response. If x is 10 and a write sets it to 20, a read after that returns 20.
An available system gives a response within the time guaranteed in its service level agreement. A system that promised three hours and took six has timed out.
The two fight wherever there is parallel processing or concurrency:
- A server answers a request for Brad Pitt's profile from its cache while his profile update runs in parallel. The read is processed at timestamp 5, the cache is updated at 6, and the response is the old profile.
- The update goes to the US database, and readers in India query the India database before the two are consistent.
If the US database crashes, the India system still responds with old data: consistency sacrificed for availability. With a single source of truth the profile returned is the latest, and any failure stops the responses.