Search code examples
luacassandramashapekong

Kong: Is it a good idea to store business logic and/or business data in the kong datastore?


I understand that the datastore used by Kong is used for persistently storing the configurations to enable horizontal scaling.

What I'm wondering is, would it also be possible to store actual business data in the api gateway's datasource itself and route the api based on the data read from this datasource.

eg. If a user has purchases by 3 different authors in the past, I want to show him the list of all books by those authors only. Here the order history is the business data, and showing him only those authors' books is the business logic.

After the request has been passed through the api gateway, I could normally fetch the order history of the user, and then display the required data.

But is it possible to save the order history of users in the kong datasource and write a custom plugin in lua that would fetch the author list of a user from the gateway itself and pass on the authors' ids to the required module, which could then just display the books by those authors?

And if possible, would it be advisable to do so?


Solution

  • While it could be possible by leveraging the underlying Kong DAO interface, I would generally not tie your business logic with the schemas used by Kong, simply because the DAO interface may change in the future in response to new Kong requirements, and you would have no control of your business logic if that happens (unless you also maintain the DAO implementation).

    Generally speaking I would host all of this logic in a separate service and then query the service from a Kong plugin using, for example, the internal HTTP client.