Route Webhook Events to Endpoints Using Wildcard Subscription Patterns
Last updated: November 29, 2026
Quick Overview
Webhook endpoints subscribe to dotted event types such as `invoice.payment_failed`, with `*` matching exactly one segment and a trailing `**` matching any remaining segments. Build a structure that registers and removes subscriptions and returns the endpoints that should receive a given event.
Stripe
November 29, 20260
0
0 solved
Webhook endpoints subscribe to dotted event types such as `invoice.payment_failed`, with `*` matching exactly one segment and a trailing `**` matching any remaining segments. Build a structure that registers and removes subscriptions and returns the endpoints that should receive a given event.
Every Stripe account can register webhook endpoints filtered by event type, and the dispatcher must decide fast which endpoints get each of a very high volume of events. The interviewer checks that you pick a trie over segments instead of testing every pattern, handle both wildcard kinds correctly and keep unsubscribe cheap.
What the Interviewer Expects
- Split event types and patterns on dots and store patterns in a segment trie
- Handle `*` (one segment) by exploring both the literal and wildcard child
- Handle trailing `**` by collecting endpoints stored as tails at that node
- De-duplicate endpoints matched by several patterns
- Support unsubscribe without rebuilding the trie
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you prune empty trie nodes after many unsubscribes?
- What is the worst-case matching cost with many `*` patterns, and how would you bound it?
- How would you shard this when there are millions of endpoints across accounts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
subscribe(endpoint, pattern), unsubscribe(endpoint, pattern), and match(event_type) returning a sorted list of endpoint ids. ** is only valid as the last segment and matches zero or more remai...
High-Level Design
Each trie node has children keyed by segment (including the literal *), ends (endpoints whose pattern ends exactly here) and tails (endpoints whose pattern ends with ** here). Matching is a ...