Introduction
Semaphores, within the context of software, can be used as synchronisation tools to manage how multiple processes access a shared resource.
OIC related use cases could include -
- FIFO
- Synchronisation between async integrations
- Singleton
- Scatter/Gather
- Resequencer
- etc.
This post will document a simple implementation of using semaphores to enable synchronisation between 2 async integrations. My 2 integrations are async create order and async create customer. The rule is simple - an order can only be created for an existing customer. If the customer does not exist in the customer DB, then async create order has to wait until async create customer does the necessary.
Before I begin, a BIG Shout Out to my very esteemed colleague, Antony R. for the initial idea. He also set up the whole semaphore / OCI Cache infrastructure and provided the 2 key integrations - acquire and release semaphore.
Let's begin with the semaphore implementation.
The Semaphore Implementation
Underlying this is OCI Cache -
More about the cache in a later post; now lets proceed to the 2 semaphore integrations - acquire and release -
The Create Order Use Case
Here are the 2 async integrations -
- Check if customer already exists
- If yes
- Create order for customer
- If no
- Acquire semaphore
- Invoke async create customer
- Payload will include semaphore details
- WHILE Semaphore not acquired
- Attempt to acquire the same semaphore again
- If Acquired
- Create order for customer
- Release semaphore
- Exit WHILE
The request payload is -
{ "custFirstName" : "Niall", "custLastName" : "Commiskey", "custCountry" : "Ireland", "product" : "iBike", "price" : 4999 }
async create customer
This integration does the following -
- Create customer in customer DB
- Release semaphore
{ "firstName" : "Niall", "lastName" : "Commiskey", "country" : "Ireland", "channel" : "Create Customer", "requestor" : "OIC" }
Acquiring the Semaphore
The request payload for AcquireSemaphore is as follows -
{ "channel" : "channel", "stream" : "stream", "requestor" : "job-17", "timestamp" : "2026-07-10T17:00:00Z" }
So what's the unique key here? It's the combination of channel and stream.
For this simple demo I will use the combination of firstName and lastName as the stream. I will call the channel Create Customer.
I have added the following lookup to the project -
Releasing the Semaphore
The request payload for ReleaseSemaphore is as follows -
{ "channel" : "channel", "stream" : "stream", "requestor" : "job-17" }
Implementing async create order
Otherwise, acquire the semaphore,
setting requestor to the lookup value for requestor-pre-cust-create - OIC-CreatingCust.
setting requestor to the lookup value for requestor-pre-cust-create - OIC-CreatingCust.
I then invoke the async create customer integration. This integration will create the customer in our ATP powered customer DB and then release the semaphore.
I then try to acquire the semaphore, but this time using the requestor - OIC-CreatedCust. We will continue in the WHILE loop until the semaphore has been released by the async create customer integration.
Running the Use Case
Pre-checks
No semaphores -
Semaphore created with the holder OIC-CreatingCust
Summa Summarum
This is just one case where semaphores could be applied. As stated in the introduction, others include -- FIFO
- Singleton
- Throttling
More about those later.
Cerevisia Aestiva
Today's beer is another gem from Franconia.
The Hofmuehl brewery is located in Eichstaett, about 60km away from where I'm living. The town is famous for its Catholic bishopric and it was a bishop who founded the brewery in 1492. The Securalisation laws from 1803 resulted in the state taking over the brewery, but it passed through many hands since then - including Eugène-Rose de Beauharnais, the adopted son of Napoleon Bonaparte.
Their Helles is 4.9% - a light, hoppy beer, great for hot summer evenings.

No comments:
Post a Comment