Mock Interview: Behavioral
Mock interview: behavioral focuses on collaboration patterns.
Introduction
Mock interview: behavioral focuses on collaboration patterns. Questions are open-ended ("How build undo?") and reward production stories over textbook recall. Command, Observer, State, Strategy composition wins senior loops.
The story
Asked "design undo system?" Junior: "Stack of states." Mid: "Command pattern; each command undoes itself." Senior: Command + Memento composition, snapshot vs action trade-off, operational-transform for collaborative undo, named production systems for each. Composed patterns, didn't memorize.
The business problem
Behavioral questions test composition and real-world judgment:
- Single-pattern answers: undo needs Command + maybe Memento.
- No trade-off: snapshot vs action undo — senior discusses both.
- No scale: collaborative editing needs OT/CRDT, not Command alone.
- Textbook only: no Figma/Google Docs style production reference.
The problem teams faced
Behavioral mock covers:
- Undo/redo — Command + Memento composition.
- Event systems — Observer vs pub/sub vs event bus.
- Workflow — State vs Strategy vs chain of responsibility.
- Extensibility — Open-closed via Strategy/Decorator.
Understanding the topic
Intent: Practice behavioral Q&A with composition thinking.
- Command — encapsulate action + undo.
- Memento — snapshot state for undo.
- Observer — publish domain events.
- State — object behavior varies by internal state.
Internal architecture
Undo — senior answer structure:
1. Single-user editor: Command with execute()/undo() + two stacks (undo/redo)2. Complex state: Memento snapshots on save points — memory cost trade-off3. Collaborative (Figma/Docs): Command insufficient alone — OT or CRDT layer4. Production refs: Photoshop action history (Command), Git (Memento-ish snapshots)interface Command { execute(): void; undo(): void }class Invoker {private undoStack: Command[] = []run(cmd: Command) { cmd.execute(); this.undoStack.push(cmd) }undo() { this.undoStack.pop()?.undo() }}
Visual explanation
Three diagrams cover undo composition, event bus, state machine:
Informative example
Event system — three levels:
JUNIOR: "Observer — subject notifies observers."MID: "Observer for in-process. Domain events as Observer on aggregate.Cross-service: Outbox + message broker — not in-process Observer."SENIOR: "In-process: Observer or event emitter on OrderPlaced. Distributed:Outbox ensures atomic publish with DB write. Notification servicesubscribes — Strategy per channel. Avoid sync Observer across HTTP —coupling and failure cascade. Story: 47 if-branches → Strategy rebuild."
Execution workflow
Open-ended Q
Undo, events, workflow.
Real-world use
Figma undo stack; Git reflog; Redux (Command-ish actions); Kafka event-driven microservices; workflow engines (State + Chain of Responsibility).
Production case study
Undo system three-level answers:
- Junior: stack — incomplete.
- Mid: Command — correct core.
- Senior: Command + Memento + OT mention + production refs — offer signal.
Trade-offs
- Pro: composition thinking matches real system design.
- Con: risk over-composing in simple scenarios — scope first.
Decision framework
- Undo single-user → Command stacks.
- Undo with rich state → Memento snapshots at checkpoints.
- Multi-user realtime → OT/CRDT above Command.
- In-process events → Observer; distributed → Outbox + bus.
Best practices
- Ask: single user or collaborative? sync or async? before naming pattern.
- Name one production system using the composition.
- Discuss memory cost of Memento snapshots.
Anti-patterns to avoid
- Memento every keystroke in large document — memory explosion.
- Observer across microservices via HTTP callbacks.
Common mistakes
- Strategy vs State confusion — State transitions are internal; Strategy chosen externally.
- Chain of Responsibility without guaranteed handler.
Debugging tips
- If interviewer narrows scope ("single user only") — simplify composition.
Optimization strategies
- Prepare 3 compositions: undo, events, order workflow.
Common misconceptions
- Command ≠ CQRS command — same word, different layer. Clarify in interview.
- Observer ≠ Kafka — pattern vs infrastructure.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1AdvancedQuestionDesign undo/redo?+
Answer
Follow-up
2IntermediateQuestionObserver vs pub/sub?+
Answer
Follow-up
3IntermediateQuestionState vs Strategy?+
Answer
Follow-up
Summary
You can answer behavioral questions at senior level with composition and trade-offs. Run the undo mock aloud — you own Behavioral Interview prep.