Parse and Build Hierarchical Resource Names for Cloud APIs
Last updated: November 29, 2026
Quick Overview
Given a resource name pattern like 'projects/{project}/locations/{location}/buckets/{bucket}', write functions that build a name from variables and parse a name back into variables, rejecting names that do not match.
0
0
0 solved
Given a resource name pattern like 'projects/{project}/locations/{location}/buckets/{bucket}', write functions that build a name from variables and parse a name back into variables, rejecting names that do not match.
Every Google Cloud API identifies resources by hierarchical names such as projects/p/locations/us/buckets/b, and client libraries generate helpers for them. The screen checks careful string handling, validation, and awareness of why names are collection/id pairs.
What the Interviewer Expects
- Split the pattern into literal and variable segments
- Validate segment count and every literal
- Reject empty segments and slashes inside ids
- Return clear errors rather than partial results
- Explain why names are stable identifiers distinct from display names
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you support multiple patterns for the same resource type?
- How would you handle a wildcard variable that may contain slashes?
- Why do Google APIs use names instead of numeric ids in URLs?
- How would you make the parser fast for millions of calls?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
ResourcePattern(pattern)compiles a pattern once.build(**vars)returns the name; missing variables or values containing/raise errors.parse(name)returns a dict of variables or raises...
High-Level Design
A resource name alternates collection ids (literal, plural nouns) and resource ids (variables). Compiling the pattern into a list of (is_var, text) segments means parse is a single pass comparing se...