Observer Pattern: Push vs Pull Model
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
Push and pull describe where observers get the data. In push, the notification contains values selected by the subject, so every listener can see the same event snapshot. For example, PriceChanged(productId, oldPrice, newPrice, version) preserves the values that caused the event. In pull, the notification is small and each listener queries the subject or another source; that may reduce payload size but adds reads and can return state newer than the triggering change. Many systems use a hybrid by pushing an ID, version, and essential values, then fetching optional details. I choose based on snapshot accuracy, payload stability, query cost, and consumer coupling.
Observer Pattern: Push vs Pull Model
Direct Answer
In push delivery, the notification contains data chosen by the subject. In pull delivery, the notification is small and the observer queries the subject or another source. Push can give a stable event snapshot but may include unused fields; pull can reduce payload size but increases coupling, extra reads, and the risk that state changes before it is read. Many systems use a deliberate hybrid.
Common Mistakes & Pitfalls
- Always choosing push because it's easier — broadcasting a 5KB object to 20 observers that need one field wastes memory and CPU.
- Pull without a subject reference — if
update()carries no reference, observers have nothing to query. - Mixing push and pull inconsistently — passing some data and expecting observers to fetch the rest muddies the contract; pick one.
- Pushing mutable state — handing observers your live collection lets them mutate the subject; return copies.
Check your understanding
Answer these without looking back at the article.
- Which model does Java's PropertyChangeListener use?
- How does reactive programming relate to the Observer pattern?
- Why should you push copies rather than live mutable state?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.