In this blog, we will go over how to use a low-code solution to author business logic for the Kinvey platform.
Specifically, we will see how to deploy a Corticon.js decision service as a Serverless service in Kinvey. The Corticon decision services are deployed as Kinvey FlexFunction, a specific sub-type of Kinvey FlexService.
Once deployed in Kinvey, decision services can be used for multiple purposes. For example:
What’s the value of doing all of this? Essentially, this mechanism allows to develop business logic:
One of the key productivity elements is that the business logic can be authored and maintained by business analysts that are comfortable using a spreadsheet.
The logic is expressed in a spreadsheet-like interface as a set of conditions and a set of corresponding actions when the conditions are met. To illustrate, we will use a simplified example of a car insurance charging customers based on daily usage. In the image below, if we take the Conditions panel column 1, we can see that the business analyst expressed that when the driver’s age is 18 to 25 and the distance driven today is between 1 and 29, and if the driver has 2 years or less of experience, then charge 4.58.
You can see how succinct this is. No complex if statements or nested if statements.
Typically, these rules are chained together in a flow to form a complex decision service. In this simplified example we have:
Where we first compute some the daily charge, as we saw, then we compound based on the zone driven and finally adjust the price based on vehicle cost. Of course, all of these could be in a single rule sheet but decomposing the service into separate units provide flexibility, reuse and easier maintenance. Not to mention that in real life, the logic is much more complex than depicted here and multiple analysts need to work in parallel on the problem at hand.
As you can see, this is a very productive way to author and maintain logic. It scales very well. We have customers implementing thousands of rules in single decision services (yes, doing business is complex!).
When the logic is ready or updated, a new service can be generated interactively in a single command. Here is a screenshot on how this is achieved:
Of course, the same can be achieved via command line tools for integration with a CI/CD system.
This command will generate a single decision service file containing the execution engine and the business logic (we call that a bundle). This JavaScript bundle is ready for deployment with the usual Kinvey mechanisms.
Deployment is typically done with the business handing over the business logic assets to IT, most likely in a source control system and as part of a CI/CD pipeline. As the deployments are done via a command line interface (node based), it can also be done interactively. See the appendix section on how to install the necessary tools.
If you choose to deploy interactively, you simply use the command:
kinvey flex deploy
And then you can check when the service is online and ready by using the command:
kinvey flex status
Here is an example:
Now the service is ready. It can be used interactively as a REST API. For example, a driver would like to check on his mobile how much today driving has cost. Or we can imagine that when the records are coming into the Kinvey collection, a collection hook (On record save) would process the data and compute how much to charge. The same service could be used on a set of driver’s records with a scheduled job. For example, we could imagine that the processing would be done in batch mode.
The important point here from a productivity point of view is that the business analysts didn’t have to know or worry about these use cases. The decision service as authored in the spreadsheet-like interface is automatically capable to work on multiple items or a single one.
You can check this video for a deployment example.
By pairing Corticon.js with Kinvey, users have the option to develop business logic very quickly and as importantly maintain it with unprecedented efficiency and productivity. In a world of IT not being able to tackle all the demands at hand, this is a lifesaver.
Thierry Ciot is a Software Architect on the Corticon Business Rule Management System. Ciot has gained broad experience in the development of products ranging from development tools to production monitoring systems. He is now focusing on bringing Business Rule Management to Javascript and in particular to the serverless world where Corticon will shine. He holds two patents in the memory management space.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites