mediumConceptDesignMidSeniorStaff
When would you use the observer pattern, and what goes wrong with it at scale?
4 min readUpdated 2026-08-15
Answer
Short answer
Observer decouples a subject from things that react to it, which is right when the subject genuinely should not know its listeners. The costs are a control flow you cannot read from the code, listener lifetimes that leak, and an exception in one observer that silently prevents the rest from running.
Mention behavioural patterns where it changes the risk, the owner, or the next check. A useful behavioural patterns point should make the answer more testable, not merely longer. Tie behavioural patterns back to the scenario so the interviewer can see why it matters here.
Was this answer helpful?
Likely follow-ups
- One observer throws. What should happen to the other five, and who decides?
- Why do observers leak, and what does a weak reference actually fix?
- Should a listener be notified on the publisher's thread? What changes if not?
- At what point would you replace an in-process observer with a message broker?
Related questions
- Give me a real single-responsibility violation you have seen, and how would you refactor it?mediumAlso on coupling5 min
- When would you use the strategy pattern instead of inheritance?mediumAlso on behavioural-patterns5 min
- Service A needs something from service B. When should that be a synchronous call and when should it be an event?mediumAlso on coupling4 min
- Adapter, decorator and facade - what concrete problem does each one solve, and where would reaching for it be over-engineering?mediumAlso on coupling7 min