Senior · Design · Conditional GET and representation validators

Design conditional reads for a resource with multiple representations and changes, including parsed header lists and a consumer with a prior body.

Think through your answer before opening the explanation.

Production engineering

Reveal answer and reasoning

Design validators around the representation and its variation dimensions, then apply the standard comparison appropriate to the method and precondition. Preserve empty304 and current200 checks, plus real parsed-list cases. The portable known-tag result can explain the comparison but cannot prove HTTP behavior. Record whether the endpoint is public, how variants are selected and what cache policy is intended instead of interpreting an ETag as permission to share every response.

A correct conditional read is a narrow efficiency and consistency contract; it supplies neither identity trust nor automatic write-conflict resolution.

For a resource with several representations, choose whether validators are shared only when their semantics genuinely permit it. Test content negotiation and any user-specific variation independently, and ensure version maintenance covers the fields actually serialized. Use standard header APIs for lists and wildcard grammar rather than concatenating a string comparison. A consumer test should distinguish a current full response from a304 using an earlier representation.

Do not attach a validator to security meaning or assume that a successful weak read proves a request is allowed to mutate the resource.

What a strong answer covers

  • The known-string helper prints True,True,False and is not a general header parser.
  • Actual matching read conditions return304 with no body; a nonmatch returns200.
  • Validator identity, cache-sharing policy and authorization are separate contracts.

Common pitfall

Treating a weak read match as write permission or an ETag as a complete cache and authorization policy.

Follow-up questions

  1. What happens when a serialized field changes without advancing the validator?
  2. How would negotiated or user-specific representations affect validator ownership?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions