RPC Server & Client

RPC Server & Client #

While Java applications typically embed Repository and DirectDataOperator directly, polyglot services (Python, Go, Node.js, etc.) and lightweight edge clients that lack direct network access to Kafka, Cassandra, or HBase can interact with Proxima over gRPC.

Proxima ships three modules for RPC communication:

  • cz.o2.proxima:proxima-server-rpc-proto: Protocol Buffer / gRPC definitions (rpc.proto, Java package cz.o2.proxima.direct.server.rpc.proto.service) defining IngestService and RetrieveService.
  • cz.o2.proxima:proxima-ingest-server-grpc: The gRPC server (cz.o2.proxima.direct.server.IngestServer) wrapping Repository and DirectDataOperator.
  • cz.o2.proxima:proxima-ingest-client: High-throughput Java client (cz.o2.proxima.direct.client.IngestClient) with automatic bulk batching, reconnection, and synchronous retrieval helpers.

gRPC Services Overview #

rpc.proto exposes two gRPC services:

IngestService (Writes & Transaction Commits) #

RPC MethodTypeDescription
ingestBulk(stream IngestBulk) → stream StatusBulkBidirectional streamHigh-throughput batched ingestion. Responses arrive asynchronously as StatusBulk messages matched by request uuid.
ingestSingle(stream Ingest) → stream StatusBidirectional streamStreaming ingestion for individual Ingest messages.
ingest(Ingest) → StatusUnarySynchronous single upsert, delete (delete = true), or wildcard delete (attribute = "prefix.*", delete = true).
commit(TransactionCommitRequest) → TransactionCommitResponseUnaryCommits an open RPC transaction (COMMITTED, REJECTED, or FAILED).

Ingest Status codes: 200 (OK), 400 (Bad Request), 404 (Entity/attribute not found), 412 (Invalid scheme payload), 500 (Internal error), 502 (Bad gateway), 504 (Timeout).

RetrieveService (Reads, Scans & Transaction Begin) #

RPC MethodTypeDescription
get(GetRequest) → GetResponseUnaryFetch a single attribute value and timestamp by (entity, key, attribute).
listAttributes(ListRequest) → ListResponseUnaryList wildcard attributes by (entity, key, wildcardPrefix) with optional pagination offset and limit.
multifetch(MultifetchRequest) → MultifetchResponseUnaryExecute multiple GetRequest and ListRequest operations in a single round-trip (preserving order).
begin(BeginTransactionRequest) → BeginTransactionResponseUnaryOpen a new ACID transaction (optionally declaring attributesInvolved) and receive a transactionId.
scan(ScanRequest) → stream ScanResultServer streamStream a full scan of attributes belonging to the same attribute family.

Retrieve status codes: 200 (OK), 204 (Already committed transaction), 400 (Bad request), 404 (Not found), 500 (Internal server error).

Starting the RPC Server (IngestServer) #

IngestServer loads your HOCON configuration, initializes Repository and DirectDataOperator (plus TransactionContext automatically if _transaction is configured), and binds both IngestService and RetrieveService to a gRPC port.

Server Configuration Properties #

HOCON KeyDefaultDescription
ingest.server.port4001TCP port the gRPC server listens on.
ingest.server.num-threads10 * max(2, cores)Worker thread pool size.
ingest.ignore-errorsfalseIgnore non-fatal initialization errors when loading optional families.

Launching the Server #

# Load reference.conf / application.conf from classpath
java -cp my-proxima-server.jar cz.o2.proxima.direct.server.IngestServer

# Or specify an explicit HOCON file path
java -cp my-proxima-server.jar cz.o2.proxima.direct.server.IngestServer /etc/proxima/application.conf

Note: IngestServer handles gRPC ingestion and retrieval only. Run ReplicationController as a separate process/deployment to replicate updates from primary commit logs to replica storages and execute transformations.

Using the Java IngestClient #

Add cz.o2.proxima:proxima-ingest-client to your project. IngestClient automatically batches outgoing Ingest messages over ingestBulk, flushes periodically, tracks in-flight requests by UUID, and retries on transient channel drops:

import com.google.protobuf.ByteString;
import cz.o2.proxima.direct.client.IngestClient;
import cz.o2.proxima.direct.client.Options;
import cz.o2.proxima.direct.server.rpc.proto.service.Rpc;

Options opts = new Options()
    .setFlushUsec(100_000)      // flush buffered bulk every 100 ms
    .setMaxInflightRequests(1000);

try (IngestClient client = IngestClient.create("localhost", 4001, opts)) {
  // 1. Asynchronous batched write (upsert)
  client.ingest(
      "user-1",
      "user",
      "details",
      ByteString.copyFrom(userDetails.toByteArray()),
      status -> {
        if (status.getStatus() == 200) {
          log.info("Ingested successfully (uuid={})", status.getUuid());
        } else {
          log.error("Ingest failed {}: {}", status.getStatus(), status.getStatusMessage());
        }
      });

  // 2. Delete an attribute
  client.delete("user-1", "user", "preferences", status ->
      log.info("Delete status: {}", status.getStatus()));

  // 3. Synchronous random-access get
  Rpc.GetResponse getResp = client.get("user", "user-1", "details");
  if (getResp.getStatus() == 200) {
    UserDetails details = UserDetails.parseFrom(getResp.getValue());
    log.info("Fetched user details: {}", details);
  }

  // 4. List wildcard attributes
  Rpc.ListResponse listResp = client.listAttributes(
      Rpc.ListRequest.newBuilder()
          .setEntity("user")
          .setKey("user-1")
          .setWildcardPrefix("event")
          .setLimit(20)
          .build());
  for (Rpc.ListResponse.AttrValue attr : listResp.getValueList()) {
    log.info("Attribute {} @ {}", attr.getAttribute(), attr.getStamp());
  }
}

Using Raw gRPC Stubs (Java & Python) #

Because the protocol is defined in standard rpc.proto, you can generate clients in any gRPC-supported language (see example/pyclient/ in the repository for a complete Python client).

Python Example #

import uuid
import grpc
import rpc_pb2
import rpc_pb2_grpc

channel = grpc.insecure_channel("localhost:4001")
ingest_stub = rpc_pb2_grpc.IngestServiceStub(channel)
retrieve_stub = rpc_pb2_grpc.RetrieveServiceStub(channel)

# Write an attribute
status = ingest_stub.ingest(
    rpc_pb2.Ingest(
        uuid=str(uuid.uuid4()),
        entity="user",
        attribute="details",
        key="alice",
        value=serialized_user_details_bytes,
    )
)
assert status.status == 200

# Read it back
resp = retrieve_stub.get(
    rpc_pb2.GetRequest(entity="user", key="alice", attribute="details")
)
if resp.status == 200:
    print(f"Found value ({len(resp.value)} bytes) at stamp={resp.stamp}")

ACID Transactions over gRPC #

Clients can execute ACID transactions remotely across RetrieveService and IngestService:

  1. Call RetrieveService.begin(BeginTransactionRequest) to obtain a transactionId.
  2. Perform all reads (get, listAttributes, or multifetch) with .setTransactionId(transactionId). The server tracks read keys automatically in the transaction state.
  3. Submit all writes via IngestService.ingest(...) with .setTransactionId(transactionId) (writes are buffered server-side in TransactionContext).
  4. Finalize with IngestService.commit(TransactionCommitRequest). If the response status is REJECTED, retry the transaction loop from step 1.