Closed microwavekonijn closed 4 years ago
Small note: I talked with Maelstome and the idea is to move the database of the websocket to the API completely. That takes some problems with sharing a database out of the equation.
@microwavekonijn can you update your original proposal in light of the decision of making the application API centric?
Yeah, I will rewrite it tomorrow with some additional considerations. I will also create a new linked issue for the websocket.
Accepted proposition, confirmed to use Nest JS for the API Framework
I want to make a start with setting up a basic api using Nest JS. I want to choose that mainly because of a few reasons. First it is same language as the websocket and will be similar to the choice for the front-end of the website. This means we can reuse utilities and models across the different services. Second it has integration for a websocket server.
I terms of where this service will sit across the other services will be as follows:
With that said we will do something similar to Laravel Airlock/Sanctum to authenticate the site, and also allow the generation of API keys(maybe even OAuth) for third-party services. The API will be in charge of allowing retrieval of data, account management, and administrative tasks(e.g. planning custom events).
Now on the real problem of implementing a real time data stream to clients. The problem is that the websocket updates the data and is not able to talk (at least in a good way) to the API service, that and the fact that we might want to scale the API makes it so that we should look at a more passive system. My proposition would be to let the API pull the most recent data and send it to the clients directly every so often(we could even filter it so only changed data is send). This way we have full control over the stream of data(e.g. rate of sending data) and it would resolve some of the issue of the old websocket server(e.g. race condition). Note that this implementation is only necessary for ongoing alerts/events, we can have an initial api call that tells the client whether to get the data from the api or from the websocket(data will always be available from the api, the websocket can always send an event to tell the client to get it from the api because of the end of an alert).
I know that the current project is written in PHP and that Laravel/Lumen has been discussed, however there are some downsides to those. Mostly the lack of good maintained Mongo ODMs, and the fact that it can't act as a websocket server.
Before I conclude there are some choices to make when using Nest JS as it is pretty agnostic.
Other services that might be interesting to look at are Kafka and RabbitMQ to handle events across services.