Can I load an initial value for an entity from my own DB?

An excellent question from the Akka Serverless Developer Workshop, with a reply from Leon:

When you create the class for your entity, the constructor can do anything a Java app can do (like loading data from a database). So in order to load the initial state from a database as opposed to starting with a blank slate, the only thing you’d need to do is add a JDBC connection to your constructor and make sure your database accepts connections from Akka Serverless when you deploy it.

:eyes: every entity instance would get initialised visiting a DB; a least for their first use? How would that scale and, why can’t the proxy do that for the entity?

I believe this comes down to the initial “cold start” for entities, which after they are started the first time then they are in “hot state” mode. I’ll ask @retgits for some more context here :-)

1 Like

Thanks @oliver-white
I tought entity contexts are created for every init message and entities are not recycled after use, so using the construtor to connect a database would lead to a hit to the db for every entity that is init-ed and then “run” by AS. If the initial state of an entity, with its own id, has to be fetched by asking a DB, I’d consider this as an antipattern. Think of that peak load for a service, where the DB would be probably overwhelmed by all those functions connecting over.

Otherwise, I’m curious about how AS maintains hot or warm entities these days.