Coherence Implementation

Here is an outline of a possible implementation of the Matching Engine, using Oracle Coherence.
The client side places an order by inserting a Bid/Offer into Order Cache [IN.STX.Q.ORDER] with index as UUID of the Bid/Offer The client then listens to the change event for the UUID of the Order.
Order States are as follows:

A CacheListner listens to insert events Validates by consulting the Validation Cache [IN.STX.SYS.VALIDATE] if OK then places the Order in respective Matching Engine Cache.  This is an OSGi service

For Each Stock Code there exists a Matching Engine, which is an OSGi service. It embeds the Matching Engine.
When an Order Matches it sends it to Order Matched Cache [IN.STX.Q.MATCHED]

Another OSGi service listens to the Order Matched Cache [IN.STX.Q.MATCHED] on insert events. On Insert event, it Updates the [IN.STX.Q.ORDER] cache; It also updates TBT (Tick By Tick) Cache [IN.STX.Q.TBT]

Crash Recovery and HearBeat Cache.

Each Matching Engine instance generates an UUID during Init(), in the Heart Beat cache [IN.STX.SYS.HEATBEAT], it first checks if the Ticker exists eg. IN.STX.ICIBAN
if exits then log error and exit, else, lock it and insert itself with timeout, update it on regular interval.

A Cache filter or event listner, monitors the heart beat, if not found then sends alert event.


1. The design does not considers the scenario, that an inflight order can be cancelled by the stock trader.