Match Request Paths Against a Volcano Engine API Gateway Route Trie
Last updated: November 29, 2026
Quick Overview
Build a router that registers templates like /v1/videos/:id/comments and /v1/static/*, then matches a concrete path to the best route and returns captured parameters, preferring literal segments over parameters over catch-alls.
ByteDance
November 29, 20260
0
0 solved
Build a router that registers templates like /v1/videos/:id/comments and /v1/static/*, then matches a concrete path to the best route and returns captured parameters, preferring literal segments over parameters over catch-alls.
Volcano Engine, ByteDance's cloud business, runs API gateways that route millions of requests per second to backend services. This onsite question checks whether you can model hierarchical paths as a trie, define a clear precedence rule, and notice that a greedy walk fails when the literal branch dead-ends and a parameter branch would have matched.
What the Interviewer Expects
- Store routes in a segment-level trie, not a character trie
- Apply precedence: literal, then named parameter, then catch-all
- Backtrack when a higher-precedence branch fails deeper in the path
- Return captured parameters cleanly without leaking state between branches
- Detect conflicting registrations such as two parameter names at one level
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 bound worst-case backtracking for adversarial route tables?
- How would you add HTTP method dispatch and per-route middleware?
- How do you hot-swap the route table without locking the request path?
- Would you compile this into a flat table for faster lookups?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Templates are split on /. A segment starting with : captures one path segment into a named parameter. * must be last and captures the remainder. Matching must return the template plus parameters...
High-Level Design
Each trie node holds a dict of literal children, at most one parameter child (with its name), an optional catch-all template, and an optional route template ending exactly here. Matching is a depth-fi...