Skip to content
Gal Koren edited this page Nov 12, 2020 · 2 revisions

What is PL

At Kenshoo, we need to persist entities to DB in bulks, we need it to perform fast and we have tons of business logic on the way like validators, enrichers, etc…
So we wrote PL, a Java library built for performance that allows us to define a flow for the business logic.
It currently supports only MySQL.
Like any other framework, some wiring and definitions are required before you can start building and executing commands.
Let’s first start with executing commands so you can get a taste of the user experience, and the rest of the book will be dedicated to the wiring and flow definition.

How Fast is PL

Compared to our old service layer, which used to persist entities one-by-one and run validations one-by-one (where each validation might access the DB to fetch some required context), moving to PL boosted performance by a factor of 2 up to 50, depending on the complexity of the flow.

First Taste - User Experience

After some wiring, persisting a new Campaign entity shall look like this:

var cmd = new CreateCampaignCmd();

cmd.set(Campaign.NAME, "bla bla");
cmd.set(Campaign.BUDGET, 150);
cmd.set(Campaign.STATUS, Status.ToPause);

var results = campaignPersistence.update(asList(cmd));

In this sample we make use of:

  • EntityType - (The Campaign) a static declaration of fields (like BUDGET)
  • Command - (The CreateCampaignCmd) a strongly typed map from fields to values
  • EntityPersistence - executes the commands

Note that the update method accepts a list of commands because we want to encourage you to persist in bulks whenever possible. Remember that PL optimizations are most effective when working with bulks.

The result object may contain validation errors that you may want to check.

Limitations

  • Only MySQL is currently Supported
  • JOOQ DefaultTransactionProvider is not supported