Skip to content

Commit 7380cc3

Browse files
committed
editing for clarity
1 parent 15844d0 commit 7380cc3

File tree

1 file changed

+83
-72
lines changed

1 file changed

+83
-72
lines changed

graph/patterns/change-tracking.md

Lines changed: 83 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,115 @@ Microsoft Graph API Design Pattern
77

88
## Problem
99

10-
API consumers require an efficient way to acquire changes to data in Microsoft Graph, for example to synchronize an external store or to drive a change-centric business process.
10+
API consumers require an efficient way to acquire changes to data in the Microsoft Graph, for example to synchronize an external store or to drive a change-centric business process.
1111

1212
## Solution
1313

14-
API designers can enable the change tracking (delta) capability on a resource in the Graph (typically on an entity collection or a parent resource) by declaring a delta function on that resource.
14+
API designers can enable the change tracking (delta) capability on a resource in the Microsoft Graph (typically on an entity collection or a parent resource) by declaring a delta function on that resource.
15+
16+
This function returns a delta payload. A delta payload consists of a collection of annotated full or partial Microsoft Graph entities plus either a `nextLink` to further pages of original or change data that are immediately available OR a `deltaLink` to poll to get the next set of changes as they occur.
1517

16-
This function returns a delta payload. A delta payload consists of a collection of annotated full or partial entities in standard Graph format plus either a nextLink to further pages of original or change data that are immediately available OR a deltaLink to poll to get the next set of changes as they occur.
1718
Annotations allow the delta payload to indicate resources or links which have been deleted. API callers are expected to differentiate resource adds from updates by interpreting the id property of the change records against the existence of resources in whatever external system is doing the processing.
1819

19-
## When to use this pattern
20+
The pattern requires a sequence of requests.
21+
22+
1. GET request on the delta function, which returns the first page of the current state of the resources that delta applies to.
23+
2. [Optionally] Further GET requests to retrieve more pages of the current state via the `@odata.nextLink` URL.
24+
3. After some time, a GET request to see if there are new changes via the `@odata.deltaLink`URL.
25+
4. [Optionally] GET requests to retrieve more pages of changes via the `@odata.nextLink` URL.
2026

21-
API consumers want a pull mechanism to request and process change to Graph data, either via proactive polling or by responding to Graph notifications.
22-
API producers can provide a low data latency (sub-minute at P95).
23-
When API consumers need guaranteed data integrity over the set of changes to Graph data.
27+
The `nextLink` provides a mechanism to do server-driven paging through the change data that is currently available. When there are no further pages of changes immediately available, a `deltaLink` is returned instead.
2428

25-
## Issues and considerations
29+
The `deltaLink` provides a mechanism for the API consumer to catch up on changes since their last request to the delta function, `deltaLink` or last page’s `nextLink`. If no changes have happened since the last request, then the deltaLink MUST return an empty collection.
2630

27-
- The pattern requires a sequence of requests.
31+
Both `nextLink` and `deltaLink` MUST be considered opaque URLs. The best practice is to make them opaque via encoding.
2832

29-
1. GET request on the delta function, which returns the first page of the current state of the resources that delta applies to.
30-
2. [Optionally] Further GET requests to retrieve more pages of the current state via the odata.nextLink.
31-
3. After some time, a GET request to see if there are new changes via the odata.deltaLink.
32-
4. [Optionally] GET requests to retrieve more pages of changes via the odata.nextLink.
33+
Delta payload requirements
34+
- The payload is a collection of change records using the collection format.
35+
- The change records are full or partial representations of the resources according to their resource types.
36+
- When a change representing a resource update is included in the payload the API producer MAY return either the changed properties or the full entity. The ID of the resource MUST be included in every change record.
37+
- When an entity is deleted, the delta function MUST return the ID of the deleted entity as well as an `@removed` annotation with the reason field.
38+
- When an entity is deleted, the reason MUST be set to “changed” if the entity can be restored.
39+
- When an entity is deleted. the reason MUST be set to “deleted” if the entity cannot be restored.
40+
- There is no mechanism to indicate that a resource has entered or exited the dataset based on a change that causes it to match or no longer match any `$filter` query parameter.
41+
- When a link to an entity is deleted, when the linked entity is deleted, or when a link to an entity is added, the implementer MUST return a `property@delta` annotation.
42+
- When a link to an entity is deleted, but the entity still exists, the reason MUST be set to `changed`.
43+
- When a link to an entity is deleted along with the entity, the reason MUST be set to `deleted`.
44+
45+
API producers MAY choose to collate multiple changes to the same resource into a single change record.
46+
47+
## When to use this pattern
3348

34-
API producers MAY respond to standard Graph OData query parameters with the initial call to the delta function:
49+
API consumers want a pull mechanism to request and process change to Microsoft Graph data, either via proactive polling or by responding to Microsoft Graph notifications.
50+
51+
API consumers need guaranteed data integrity over the set of changes to Microsoft Graph data.
52+
53+
## Issues and considerations
54+
55+
- API service MAY be able to respond to standard OData query parameters with the initial call to the delta function:
3556

3657
- `$select` to enforce the set of properties on which change is reported.
3758
- `$filter` to influence the range of changes returned.
3859
- `$expand` to include linked resources with the set of changes.
3960
- `$top` parameter to influence the size of the set of change records.
4061

41-
These query parameters MUST be encoded into subsequent odata.nextLink or odata.deltaLink, such that the same options are preserved through the call sequence without callers respecifying them, which MUST NOT be allowed.
62+
These query parameters MUST be encoded into subsequent `@odata.nextLink` or `@odata.deltaLink`, such that the same options are preserved through the call sequence without callers respecifying them, which MUST NOT be allowed. OData query parameters must be honored in full, or a 400-error returned.
4263

43-
Making a sequence of calls to a delta function followed by the opaque urls in the nextLink and deltaLink MUST guarantee that the data at the start time of the call sequence and all changes to the data thereafter will be returned at least once. It is not necessary to avoid duplicates in the sequence. When the delta function is returning changes, they MUST be sequenced chronologically refer to [public documentation](https://learn.microsoft.com/en-us/graph/delta-query-overview?view=graph-rest-1.0) for more details.
64+
- Making a sequence of calls to a delta function followed by the opaque URLs in the `nextLink` and `deltaLink` MUST guarantee that the data at the start time of the call sequence and all changes to the data thereafter will be returned at least once. It is not necessary to avoid duplicates in the sequence. When the delta function is returning changes, they MUST be sequenced chronologically refer to [public documentation](https://learn.microsoft.com/en-us/graph/delta-query-overview?view=graph-rest-1.0) for more details.
4465

4566
- The delta function can be bound to a collection, as with
46-
`/users/delta` – this returns the changes to the users' collection.
47-
48-
or to some logical parent resource, where the change records are implied to be relative to all collections contained within the parent, for example
49-
`/me/planner/all/delta` – this returns changes to any resource within planner that a user is subscribed to as a heterogenous collection.
50-
- Delta payload requirements
51-
- The payload is a collection of change records using the standard Graph collection format.
52-
- The change records are full or partial representations of the resources that changed using the standard Graph types for the resources.
53-
- When a change representing a resource update is included in the payload the API producer MAY return either the changed properties or the full entity. The id of the resource MUST be included in every change record. - The nextLink provides a mechanism to do server-driven paging through the change data that is currently available. When there are no further pages of changes immediately available, a deltaLink is returned instead.
54-
- The deltaLink provides a mechanism for the API consumer to catch up on changes since their last request to the delta function, deltaLink or last page’s nextLink. If no changes have happened since the last request, then the deltaLink MUST return an empty collection.
55-
- Both “nextLink” and “deltaLink” MUST be considered opaque URLs. The best practice is to make them opaque via encoding.
56-
- When an entity is deleted, the delta function MUST return the ID of the deleted entity as well as an @removed annotation with the reason field.
57-
- When an entity is deleted, the reason MUST be set to “changed” if the entity can be restored.
58-
- When an entity is deleted. the reason MUST be set to “deleted” if the entity cannot be restored.
59-
- There is no mechanism to indicate that a resource has entered or exited the dataset based on a change that causes it to match or no longer match any $filter query parameter.
60-
- When a link to an entity is deleted, when the linked entity is deleted, or when a link to an entity is added, the implementer MUST return a “property@delta” annotation.
61-
- When a link to an entity is deleted, but the entity still exists, the reason MUST be set to “changed”.
62-
- When a link to an entity is deleted along with the entity, the reason MUST be set to “deleted”.
63-
- OData query parameters must be honored in full, or a 400-error returned.
67+
`/users/delta` that returns the changes to the users' collection.
68+
69+
or to some logical parent resource, where the change records are implied to be relative to all collections contained within the parent, for example
70+
`/me/planner/all/delta` – this returns changes to any resource within planner that a user is subscribed to as a heterogenous collection.
6471

65-
## Alternatives ##
72+
- Although this capability is similar to the OData `$delta` feed capability, it is a different construct. Microsoft Graph APIs MUST provide change tracking through the delta function and MUST NOT implement the OData `$delta` feed when providing change tracking capabilities to ensure the uniformity of the API experience.
73+
- API producers might use `$skipToken` and `$deltaToken` within their implementations of `nextLink` and `deltaLink`, however the URLs are defined as being opaque and the existence of the tokens MUST NOT be documented. It is not a breaking change to modify the structure of `nextLinks` or `deltaLinks`.-
74+
- `nextLink` and `deltaLink` URLs are valid for a specific period before the client application needs to run a full synchronization again.For `nextLink`, a minimal validity time should be 1 hour. For `deltaLink`, a minimal validity time should be seven days. When a link is no longer valid it must return a standard error with a 410 GONE response code.
75+
6676

67-
- Change notifications pattern with rich payloads – for use cases where API consumers would find calling back into Graph onerous and absolute integrity guarantees are less critical.
77+
## Alternatives
78+
79+
- Change notifications pattern with rich payloads – for use cases where API consumers would find calling back into Microsoft Graph onerous and absolute integrity guarantees are less critical.
6880

6981

7082
## Examples
7183

72-
### Delta payload
84+
### Change tracking on entity set
85+
86+
```
87+
<Function Name="delta" IsBound="true">
88+
<Parameter Name="bindingParameter" Type="Collection(Microsoft.DirectoryServices.user)" />
89+
<ReturnType Type="Collection(Microsoft.DirectoryServices.user)" />
90+
</Function>
91+
<EntitySet Name="users" EntityType="Microsoft.DirectoryServices.user">
92+
<Annotation Term="Org.OData.Capabilities.V1.ChangeTracking">
93+
<Record>
94+
<PropertyValue Property="Supported" Bool="true" />
95+
</Record>
96+
</Annotation>
97+
</EntitySet>
98+
```
99+
100+
### Change tracking on navigation property
101+
102+
```
103+
<Function Name="delta" IsBound="true">
104+
<Parameter Name="bindingParameter" Type="Collection(microsoft.education.rostering.api.educationClass)" />
105+
<ReturnType Type="Collection(microsoft.education.rostering.api.educationClass)" />
106+
</Function>
107+
<EntityType Name="educationRoot">
108+
<NavigationProperty Name="classes" Type="Collection(microsoft.education.rostering.api.educationClass)" ContainsTarget="true">
109+
<Annotation Term="Org.OData.Capabilities.V1.ChangeTracking">
110+
<Record>
111+
<PropertyValue Property="Supported" Bool="true" />
112+
</Record>
113+
</Annotation>
114+
</NavigationProperty>
115+
</EntityType>
116+
```
117+
118+
### Delta payload
73119

74120
Here, a user resource is updated, and there is one user added to and one removed from that user’s directReports collection. Additionally, a second user is deleted. In this case, there are no further pages of change records currently available.
75121

@@ -112,39 +158,4 @@ GET https://graph.microsoft.com/v1.0/users/delta
112158
}
113159
]
114160
}
115-
```
116-
117-
### API producer CSDL examples
118-
119-
EntitySet example
120-
```
121-
<Function Name="delta" IsBound="true">
122-
<Parameter Name="bindingParameter" Type="Collection(Microsoft.DirectoryServices.user)" />
123-
<ReturnType Type="Collection(Microsoft.DirectoryServices.user)" />
124-
</Function>
125-
<EntitySet Name="users" EntityType="Microsoft.DirectoryServices.user">
126-
<Annotation Term="Org.OData.Capabilities.V1.ChangeTracking">
127-
<Record>
128-
<PropertyValue Property="Supported" Bool="true" />
129-
</Record>
130-
</Annotation>
131-
</EntitySet>
132-
```
133-
134-
NavigationProperty example
135-
136-
```
137-
<Function Name="delta" IsBound="true">
138-
<Parameter Name="bindingParameter" Type="Collection(microsoft.education.rostering.api.educationClass)" />
139-
<ReturnType Type="Collection(microsoft.education.rostering.api.educationClass)" />
140-
</Function>
141-
<EntityType Name="educationRoot">
142-
<NavigationProperty Name="classes" Type="Collection(microsoft.education.rostering.api.educationClass)" ContainsTarget="true">
143-
<Annotation Term="Org.OData.Capabilities.V1.ChangeTracking">
144-
<Record>
145-
<PropertyValue Property="Supported" Bool="true" />
146-
</Record>
147-
</Annotation>
148-
</NavigationProperty>
149-
</EntityType>
150161
```

0 commit comments

Comments
 (0)