liveBook · Manning

Semantic lock

As explained in Microservices Patterns, Second Edition

A semantic lock is an application-level record flag or locking convention that indicates an uncommitted value may change and should be restricted or treated cautiously.

A semantic lock is an application-level flag on a record created or updated by a saga. It signals that the value is uncommitted and may change, so other transactions can be restricted or treat it cautiously. section 9.3.2

Use the flag to signal in-progress work; it can function in either of two ways:

  • Prevent other transactions from accessing the record. section 9.3.2
  • Warn other transactions to handle the record cautiously. section 9.3.2

Order creation

An Order can use a *_PENDING state to signal that a saga is updating it. In the FTGO Create Order Saga, semantic locks are used for both Order and Ticket entities so other transactions can detect and handle in-progress updates. section 9.3.2 section 11.1.1

Table 11.1 The definition of the FTGO Create Order Saga

Saga canvas

System operation:

createOrder(…​)

Step

Participant

Transaction

Compensating transaction

1

Order Service

(orderId, orderTotal) = createOrder(…​)

rejectOrder(orderId)

2

Consumer Service

verifyConsumer(…​)

-

3

Kitchen Service

createTicket(…​)

rejectTicket(…​)

4

Accounting Service

authorizeCard(…​)

-

5

Order Service

approveOrder()

-

6

Kitchen Service

approveTicket()

-

Review the six-step Create Order Saga flow and its participants to see where semantic locks support concurrent updates. section 11.1.1

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines a record flag and explains its blocking or warning roles.
Examples
Uses Order pending states and the FTGO Create Order Saga's Order and Ticket entities.
What it assumes
Assumes a saga context in which separate transactions lack isolation.
What you can do after
Apply a record flag to signal that a saga's change is uncommitted and may still change.
How it connects
Connects semantic locks to sagas, transaction isolation, compensatable transactions, and other saga countermeasures.

Related concepts

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