liveBook · Manning

Strong consistency

As explained in API Design Patterns

Strong consistency is a consistency guarantee under which reads reflect the relevant latest committed state and do not proceed across conflicting modifications.

Strong consistency means a successful write is immediately visible to standard reads and remains available across list, get, update, and delete operations. It prevents a newly created resource from appearing missing because replication has not reached every node. section 7.3.5

Choose the API shape according to the consistency the storage system can actually provide:

  • Keep standard create methods strongly consistent whenever possible. section 7.3.5
  • Use a custom import method such as ImportLogEntries when newly loaded data is necessarily eventually consistent. section 7.3.5
  • Use a long-running operation when completion can be identified reliably after system-wide replication. section 7.3.5

Creating a chat room

After CreateChatRoom returns successfully, clients should be able to find the ChatRoom through list, retrieve it through get, modify it through update, and remove it through delete without encountering a replication-related 404. section 7.3.5

Listing 21.3 API definition for paging through single large resources
abstract class ChatRoomApi {
  @get("/{id=chatRooms/*/messages/*/attachments/*}:read")
  ReadAttachment(req: ReadAttachmentRequest):
    ReadAttachmentResponse;                   #1
}
 
interface ReadAttachmentRequest {
  id: string;
  pageToken: string;                          #2
  maxBytes: number;                           #3
}
 
interface ReadAttachmentResponse {
  chunk: Attachment;                          #4
  fieldMask: FieldMask;                       #5
  nextPageToken: string;                      #6
}

For paged reads of a large resource, abort the request if the resource changes during paging; continuation tokens and field masks describe each consistent chunk. section 21.3.4

How API Design Patterns covers it

How deep it goes
Defines read-after-write behavior, replication failures, alternative API shapes, and abort rules for modified paged resources.
Examples
Uses ChatRoom creation, message creation, import methods, and paged attachment reads as concrete API scenarios.
What you can do after
Design API methods that expose writes consistently or route unavoidable replication delays through explicit custom operations.
How it connects
Connects standard methods with eventual consistency, custom methods, long-running operations, pagination, continuation tokens, and field masks.

Also explained in

Compare how 2 books explain strong consistency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.