Baratine Documentation

What is Baratine?

Baratine is a distributed platform for sharded services. 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 radical 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
_images/service-inbox-outbox.png

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;

@Service("public:///my-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.

With HTTP GET:

$ curl http://localhost:8085/s/pod/my-service?m=hello&p0=my-arg
"Hello[my-arg,1]"

With Java:

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

public MyClient {
  @Inject @Lookup("/my-service")
  private HelloImpl _myService;

  public void doTest()
  {
    String value = _myService.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 = Services.getCurrentManager();

   HelloImpl myService = manager.lookup("/my-service")
                                .as(HelloImpl.class);

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

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