By Simon McWhinnie, Senior PHP developer
A long-term solution to handle event data had to be both flexible and scalable
As part of our move to a headless services architecture, we needed our WordPress CMS to push data into a content API. An initial solution, built upon existing technology and developed within WordPress, had several issues. We needed a long-term solution.
To achieve a flexible, scalable outcome, we decided to build a separate message queue service.
Built using API Platform, the message queue service accepts a message that describes an event that has occurred. Specifically, in the case of WordPress, that event is the creation, updating or deletion of a piece of content.
The message queue service then adds this message to the queue, for which we used AWS’s Simple Queue Service. Using a queue designed for this purpose gave us somewhere to store the message and meant it would only be handled once (and be able to be tried again, should it fail).
A worker picks up a message from the queue and passes on the event to that event’s dedicated handler. The handler then lets other services know what they need to do in response to that event. In our initial use case, the worker lets WordPress know that it should push the required data into the content API.
Since its launch, the message queue service has proven to be extremely reliable, with a success rate of more than 99.7%. By building it with API platform outside of WordPress, it has also allowed other services to send their own events to be handled with minimal work required by the developer.