Baratine Documentation

What is Baratine?

Baratine is a platform for building a network of loosely-coupled microservices. Baratine services are:

  • POJOs,
  • single-threaded,
  • in-memory,
  • persistent, and
  • distributed.

Baratine’s model is a single-owner/single-writer model where services own and manage their own data. A service persists data to its own local store or database that resides within the same JVM. Other services can only access that data by asking/calling that service. This means that the owning service is free to batch writes because there is no contention.

Real-time Batching for High-performance

Baratine is a real-time service engine. However, it does feature batching capabilities that are core to batching frameworks (e.g. Hadoop Map-Reduce, Apache Spark, Apache Storm, etc.) like:

  • batched processing,
  • batched writes, and
  • in-memory processing.

The key difference is that Bartine’s batching is implicit, behind-the-scenes, and mostly invisible to developers.

Batched processing is automagically provided by an Inbox queue that sends requests to your service in batches. How large those batches are is dependent on 1) how fast requests are coming in and 2) your service’s processing speed.

Batched writes and in-memory processing are available to developers because the service owns its own data and there are no contention nor corruption due to having multiple writers. In other words, there is no single database bottleneck.

Operational Data

Baratine is a shift in the traditional application model because it moves the data into the owning service. It’s the only writer; there is no contention. Since the service also has the code that updates the data, it can calculate results directly using its in-memory model. The in-memory model is a cache of sorts, but unlike traditional caches its plain operational data, usable directly and never out of sync.

Baratine’s model is a return to application simplicity. Services operate on their own domain-specific models, instead of mapping to database-centric models.

POJO @Service

A Baratine service is composed of:

  • a POJO service object,
  • an inbox queue, and
  • an outbox queue

When you deploy your code, Baratine attaches an inbox and an outbox to your service. The inbox proxies requests as method calls on your service object. The inbox is single-threaded and method calls are invoked sequentially and in order. The outbox batches return results and outgoing calls for output efficiency and thoroughput.

package example;

import io.baratine.core.Service;

public MyHelloImpl
  private int _counter;

  public String hello(String arg)
    int count = ++_counter;

    return "Hello[" + count + "," + arg + "]";

Simple Client

Services can be called by Java, WebSocket, and HTTP clients.


$ curl http://localhost:8085/s/pod/my-service?m=hello&p0=my-arg

With Java:

import javax.inject.Inject;
import io.baratine.core.ServiceClient;

public MyClient
  public void doTest()
    String url = "http://localhost:8085/s/pod";

    try (ServiceClient client = ServiceClient.newClient(url).build()) {
      Hello hello = client.lookup("remote:///my-service")

      String value = hello.hello("my-arg");

      System.out.println("Hello: " + value);

The proxy can also be created programmatically:

 import io.baratine.core.Services;
 import io.baratine.core.ServiceManager;

 public void doTest()
   ServiceManager manager = ServiceManager.current();

   Hello myService = manager.lookup("/my-service")

   String value = myService.hello("my-arg");

   System.out.println("Hello: " + value);