I'd like to have a AWS lambda / event system that allows for a certain kind of flexability, here's what I need.
- Events come in via HTTP post webhook with headers and body
- Store
{headers, body}
in one mainevents
table where theevent
is named what the action is e.g. 'orderCreate', this acts as a ledger of events, with the main columnsname
,data
,created_at
. - I'd like to build up the state of individual object, in their own table so for
orders
a table would exist with that name the event of aorderCreated
the row is created and subsiquentorderDeleted
the row is deleted. - I need a way to tap into this event and trigger some side-effect event, for instance if a
orderCreated
comes in to the system I also need to fire something when that comes in such asinvoiceCreated
I need a way to access the stream of all events and subscribe to theorderCreated
and fire ainvoiceCreated
which ideally should repeat this process all over again.
- Store
The database technology really shouldn't matter, the queuing and messaging system does. In the example described above there is only a real need to have the following lambdas.
event-process
where events come in via HTTP or some queueing system and stores the data in the initialevents
table from there each event needs to enter the queueevent-state
where events come in from the queue and CRUD operations are set accross different tables and databases example would be iforderCreated
comes in an order is inserted into theorders
table and if anorderDeleted
event comes in the order with the specified id is deleted. Object state is maintained here.create-invoice-on-order
a side-effect lambad listening to theorderCreated
event, creates and invoice and then emits it's owninvoiceCreated
event back into the queue, and the cycle begins again.
Questions
- What AWS service should I use for this queue?
- How do you process events and allow the possibilities for many
side-effects
to operate without removing things from the queue?
Let's say we've got a new Service Webhook that came into a Lambda via a HTTP POST when an Order was Created for a specific shop.
We can split this one event into different streams.
serviceWebhook
serviceWebhookShopName
serviceWebhookShopNameOrderCreate
Now you can have three streams for each action getting more specific as you go down the list.
An alternative to this idea could be just to fire the event for the top level serviceWebhook
and then have a your Lambda filter out when to run based on the payload. So if this hook fires for ShopAlpha
and ShopBeta
the payload has a speicific property {"shop": "ShopAlpha"}
you can just throw an error if it's not the one you want and continue on with your intended Lambda operation.
There's a split between where the logic lies, and cost.
- Multiple arbitrary data pipes. (cost per pipe)
- Having the lambda fire and filter out events it doesn’t need to take action for. (cost per running functions unnecessarily)
SQS Aws' simple queue service.
Read about the visibility window for SQS messages. Basically for SQS message when it's read by a client it become not visible for a fixed period of time (extension is possible) then you either delete it to remove the message from the queue or leave it alone to become visible again.
Now thinking about side effect operating on things sounds like making multiple queue might also be a better option to simplify the programming model such that every side-effect operation might have it's own queue.