API Fundamentals
Concurrency
Concurrent writes can overwrite each other or trigger the same workflow more than once. Coordinate updates at the integration layer and use operation-specific preconditions whenever an endpoint provides them.
Current contract
How lost updates happen
1. Client A readsReceives the current resource state.
2. Client B updatesSaves a newer state for the same resource.
3. Client A writesSends an update based on stale data.
4. Change is lostClient B’s values may be overwritten.
Coordination strategies
| Strategy | Use case | Trade-off |
|---|---|---|
| Serialize per resource | Message consumers or workers updating the same entity. | Reduces parallelism for that resource but simplifies correctness. |
| Read before write | Updates based on an existing resource state. | The state can still change between the read and write without a server-side precondition. |
| Single writer | One system should own a field or lifecycle transition. | Requires clear integration ownership and routing. |
| Merge by field ownership | Several systems update different parts of one resource. | Needs an explicit ownership matrix and conflict policy. |
| Operation precondition | An endpoint explicitly exposes a version, token or conditional update mechanism. | Available only where documented by the operation. |
Serialize work by resource key
// Illustrative queue partitioning
const partitionKey = `${tenantId}:${resourceType}:${resourceId}`;
await queue.publish({
partitionKey,
command: "UpdateResource",
payload
});
// The consumer processes messages with the same partitionKey in order.
This approach is implemented by the integration or worker infrastructure; it is not an LCE request header.
Concurrency practices
- Define which system owns each mutable field and lifecycle transition.
- Prevent duplicate UI submissions and concurrent worker execution for the same resource.
- Use dedicated update models rather than sending a stale full resource representation.
- After an uncertain write, retrieve the latest state before taking another action.
- Record source system, resource identifier and operation time for conflict investigation.
- If a future endpoint exposes a version or precondition, preserve and send it exactly as documented.