Apply an Update Mask to a Nested Resource in a Patch Method

Last updated: November 29, 2026

Quick Overview

Implement the server side of a PATCH method that takes a resource and a comma-separated field mask such as 'display_name,settings.theme' and updates only those paths, validating unknown and immutable fields.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Implement the server side of a PATCH method that takes a resource and a comma-separated field mask such as 'display_name,settings.theme' and updates only those paths, validating unknown and immutable fields.

Google APIs use FieldMask on Update methods so clients can change one field without clobbering concurrent edits to others. The interviewer looks for precise semantics: what an absent field in the patch means, how wildcard '*' behaves, and how output-only fields are protected.

What the Interviewer Expects
  • Explain why full replacement loses concurrent updates
  • Walk nested paths and create intermediate objects only when needed
  • Treat a masked field missing from the patch as a clear to default
  • Reject unknown paths and output-only fields
  • Support '*' as full replacement of writable fields
Key Topics to Cover
field masks
partial update
AIP-134
PATCH semantics
validation
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How should repeated fields inside a mask behave?
  • What should happen when the mask is empty?
  • How would you combine field masks with etags?
  • How would you generate the mask on the client automatically?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • apply_mask(resource, patch, mask, schema) returns a new resource.
  • Paths are dot separated; each must exist in the schema.
  • If a masked path is present in patch, copy it; if absent, reset it t...
High-Level Design

The schema is a nested dict where leaves are (default, writable) tuples. Validation runs first so a bad request changes nothing. Application deep-copies the resource, then for each path walks the pa...


Submit Your Answer
Markdown supported