← Snowflake Interview Insights

Snowflake·Frontend Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Snowflake frontend interview, got a classic pub/sub implementation question. Pretty standard for frontend systems rounds 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.

Technical Trade-offsAPI & IntegrationsAlgorithms & Data Structures
Author's notes

The core API feels approachable until you hit the mutation-during-iteration problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (e.g., error handling, listener context, once semantics) and then implement a class using a Map or object to store event listeners. Walk through each method, explaining design choices and edge cases, and test with a few examples.

Pro tip: Mention that you'd use a Map for O(1) lookups and handle listener removal during emit by iterating over a copy of the array to avoid skipping listeners.

1. Clarify requirements

Ask about expected behavior for edge cases: emitting non-existent events, listener context (this binding), and whether once listeners should be removed before or after invocation.

2. Design data structure

Choose a Map (or object) to map event names to arrays of listener functions. Explain why Map is preferable for frequent additions/removals and non-string keys.

3. Implement on and off

Write on to add a listener to the array for the event, creating the array if needed. Write off to remove a specific listener, handling cases where the event or listener doesn't exist.

4. Implement emit and once

For emit, iterate over a copy of the listeners array and call each with provided arguments. For once, wrap the listener in a function that removes itself before calling the original, then register it with on.

5. Test and discuss trade-offs

Walk through examples: adding/removing listeners, emitting with multiple arguments, once behavior. Discuss trade-offs like memory leaks if listeners aren't removed, and potential improvements (e.g., error handling, max listeners).

Key Points to Mention

  • Use a Map or object to store event listeners for O(1) access.
  • Handle listener removal during emit by iterating over a copy of the array.
  • Implement once by wrapping the listener to remove itself before invocation.
  • Consider error handling: what happens when emitting an event with no listeners?
  • Discuss memory management: removing listeners to prevent leaks.
  • Mention potential extensions: listener context, max listeners warning, event namespaces.

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