Why is the operation for creating/registering components a run time activity versus a compile time activity?

In JavaScript, creating and entity:

const EventSourcedEntity = require("@lightbend/akkaserverless-javascript-sdk").EventSourcedEntity;

const entity = new EventSourcedEntity(
    ["shoppingcart.proto", "domain.proto"],
    "example.shoppingcart.ShoppingCartService",
    {
        persistenceId: "shopping-cart",
        snapshotEvery: 100
    }
);

For Java, registering an entity:

      new AkkaServerless()
          .registerEventSourcedEntity(
              ShoppingCartEntity.class,
              ShoppingCartApi.getDescriptor().findServiceByName("ShoppingCartService"),
              ShoppingCartDomain.getDescriptor())

With both language implementations, the link between the code and the protobuf happens at run time. Therefore any misalignment problems are not found until runtime.

Ideally, this should be done at compile time. Even with JS there are tools that would help to surface issues before running the code.

This was discussed in this project that predates AS here:

for the Go User Support Library. This is one of the libraries that is for now incompatible with AS, but is based on the same principles as of this project here.

A response to your question depends heavily on what is possible with the SDK language you’ve choosen or more precisely with the gRPC or code generation library you use with that language. Sometimes these gRPC libraries do not expose all information so that you can be ensure at compile time what the gRPC service matches your service implementation. The Go gRPC implementation is one example.

In practice, you would probably not go far without using and testing your services.

Also the use of code generation for your service defined by your API contract, the gRPC service, can help, altough they have to be provided by an SDK.
Using a protoc plugin that generates valid service stubs was one idea a colleague of yours at LB brought up some time ago here too:

it was dicsussed by the open source community then and the issue is still open.

1 Like