Using the Changed Record Queries
The Ed-Fi API platform contains data that gets updated frequently. The platform tracks inserts, updates, deletes, and key changes, and surfaces those changes to client systems through a feature called changed record queries, or "change queries." Change queries allow client systems to narrow requests for data to only data that has changed since a specified system version number. This allows client systems to stay in sync with the Ed-Fi API without having to pull a complete dataset.
About Change Queries
The Change Queries feature was designed to provide a lightweight mechanism for tracking relevant API operations for enabling system integration developers to easily retrieve and apply changed data to downstream systems. It is conceptually similar to SQL Server Change Tracking, and thus the solution has many of the same properties and considerations, such as:
- The API will return the most recent version of the resource. (This is different from a change data capture (CDC) system that provides a log of every change.)
- Synchronization processing is greatly simplified when using snapshot isolation (which isolates the API client's work from ongoing changes to the underlying source database). However, this approach is only available if the Ed-Fi API host takes some extra steps to create and make snapshots available.
- When snapshots are not available, the API client bears the ultimate responsibility for ensuring data consistency with downstream systems (guidance for implementing this type of processing is provided later in this document). A periodic full reinitialization of the target system's data (if possible) may be necessary to achieve consistency.
- When snapshots are available and used for processing, this will likely limit the frequency with which processing can be performed (due to the technical constraints around creating and providing new snapshots).
- The article on the Changed Record Queries feature has implementation details which may be of interest to some client system developers.
Overview of Change Query Endpoints
The core operations for Change Queries processing are as follows:
Snapshots
Snapshot support is planned for a future release. See Current Limitations for details.
Snapshots are configured through the Configuration Service by creating a
DataStoreDerivative record with DerivativeType = 'Snapshot' and the
snapshot database connection string, associated with the appropriate
DataStore.
The API client should set the Use-Snapshot HTTP header to true on each
request.
If a 404 Snapshot Not Found response is returned, it means that the host has not set up snapshots for change query processing.
Available Change Versions Resource
The Ed-Fi API uses a change version (as opposed to a date/time) in the form of a sequential long integer. The global Available Change Versions API resource provides information on the current change version. This resource allows clients to request just the resource items that have been created, updated, or deleted since the last synchronization processing was performed.
GET /changeQueries/v1/availableChangeVersions
{
"oldestChangeVersion": 0,
"newestChangeVersion": 100
}
Minimum and Maximum Change Version Parameters
The Minimum Change Version and Maximum Change Version parameters allow clients
to request the latest representation of all resources that were modified within
the given change version window. These parameters are available on every data
management resource, both as part of the Ed-Fi Data Standard and in extension
models. The parameters are also compatible with the existing parameters to
support paging using the offset and limit parameters. Using paging
parameters in conjunction with change version parameters, all records can be
retrieved over multiple calls.
GET /data/ed-fi/classPeriods?minChangeVersion=234378&maxChangeVersion=234974&offset=100&limit=500
Deletes Route
The "Deletes" route allows clients to get the id and the natural key
values for deleted resources. This route also supports the existing paging
parameters of offset and limit.
GET /data/ed-fi/studentProgramAssociations/deletes?minChangeVersion=234378&offset=0&limit=25