← Snowflake Interview Insights

Snowflake·Frontend Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Frontend coding round at Snowflake where they had me implement an EventEmitter class from scratch. Pretty classic question but there are enough edge cases to trip you up if you haven't thought it through carefully.

Questions Asked (1)

Q1

Implement an EventEmitter class with on, off, emit, and once methods supporting a standard pub/sub interface.

System DesignTechnical Trade-offsAPI & Integrations
Author's notes

The basic structure came to me quickly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then outline the data structure (e.g., a Map of event names to arrays of listener objects) and implement each method with careful handling of once and off during emit. Discuss trade-offs like error handling, memory management, and performance considerations.

Pro tip: Mention that you would iterate over a copy of the listeners array during emit to avoid issues when listeners are added or removed mid-emit, and consider using a Set for O(1) removal if order isn't critical.

1. Clarify Requirements

Ask about expected behavior: should emit be synchronous? How to handle errors in listeners? Should off remove all listeners for an event? This shows you think about edge cases.

2. Design Data Structure

Choose a Map or object to store event names as keys and arrays of listener objects (with callback and once flag) as values. Explain why this supports efficient add/remove.

3. Implement Core Methods

Write on, off, emit, and once. For once, wrap the callback to automatically remove itself after invocation. In emit, iterate over a copy of the listeners to avoid mutation issues.

4. Handle Edge Cases

Address scenarios like emitting an event with no listeners, removing a listener during emit, and ensuring once listeners are removed even if the callback throws.

5. Discuss Trade-offs and Extensions

Talk about synchronous vs asynchronous emit, memory leak prevention, and potential extensions like wildcard events or max listeners warning.

Key Points to Mention

  • Use a Map (or object) to store event names and their listeners for O(1) lookup.
  • For once, wrap the listener to remove itself after being called, ensuring it works even if the callback throws.
  • During emit, iterate over a copy of the listeners array to handle listeners added/removed during emission.
  • Consider error handling: should errors in listeners propagate or be caught?
  • Discuss memory management: removing listeners when no longer needed to prevent leaks.
  • Mention performance: emit should be O(n) where n is number of listeners for that event.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.