@@ -282,6 +282,11 @@ When a field represents another resource, the field **should** be of type
282282` string ` and accept the resource name of the other resource. The field name
283283** should** be equivalent to the corresponding message's name in snake case.
284284
285+ The field ** should not** be of type ` message ` using the ` message ` that
286+ implements the resource, _ unless_ the API is internal-only, has tight lifecycle
287+ relationships, and has a permission model that enables inherited access to
288+ embedded resources.
289+
285290- Field names ** may** include a leading adjective if appropriate (such as
286291 ` string dusty_book ` ).
287292- Field names ** should not** use the ` _name ` suffix unless the field would be
@@ -320,8 +325,31 @@ message Book {
320325 [ AIP-180] ( ./0180.md#changing-resource-names ) .
321326- For resource types, see [ AIP-123] [ ] .
322327
328+ ## Rationale
329+
330+ ### Disallow embedding of resources
331+
332+ Using a resource message directly as the type of a field within another resource
333+ is problematic for a number of reasons, which are as follows:
334+
335+ * Complicates the resource lifecycle: If the dependency resource is
336+ deleted, what happens to the embedded reference in the dependent resource?
337+ Data retention and clean up operations will be significantly complicated.
338+ * Bypasses permissions: If every resource has its own set of permissions, a user
339+ with read permission on the dependent resource that doesn't have the same
340+ permission on the dependency resource suddenly cannot see the full resource.
341+ * Tightly couples resources in all aspects: Changing the requirements in the
342+ schema, permissions, or otherwise for either resource impacts the other,
343+ significantly increasing complexity of roll outs.
344+
345+ Referencing by name, as is recommended, eliminates all of this complexity by
346+ preventing resource data duplication, and forcing the owning service to be
347+ involved in the resolution of the reference (via Standard Methods), guaranteeing
348+ isolation of logical concerns per-resource.
349+
323350## Changelog
324351
352+ - ** 2023-08-10** : Explicitly disallow embedding resource messages in a resource.
325353- ** 2023-03-24** : Correction: full resource name contains the service name rather
326354 than the service endpoint
327355- ** 2023-03-17** : Add ` OUTPUT_ONLY ` guidance for resource ID fields.
0 commit comments