scala - How to use actors for database access and DDD? -


i'm not quite sure how actors can used access database. in documentation , books akka topic seems omitted.

one solution can wrapped dao in stateless actor. example each table (or domain object type or aggregate type) in database 1 can create actor responsible crud operations. variation of can separation of commands , queries. example each data type 1 command actor (for concurrency) , 10 query actors (for parallelism).

an other approach create stateful actors representing 1 row (or domain object instance or aggregate instance) in database. of course database can in case event store (like akka persistence module) consistent projection database, document store or cache. that's not relevant here. approach implementation of in memory cache benefits , problems. there must strategy destroying actors not run out of memory after while.


i extend question ddd:

let's say, want develop ddd application akka actors. let's concentrate here on command part. in opinion should implemented in way: each bounded context there port actor, e.g. spray rest api, routes messages appropriate domain service actor. service actor coordinates business task 1 or more domain model aggregates. each single aggregate stateful actor restored (or created on new data) service actor database. service actor sends/routes messages involved aggregate actors. receiving domain model actors perform business validation on state + message , write changes database, e.g. slick daos. after sending done service actor stopped. when aggregate actors finished done message send sender of message. variation not stop stateful domain model actors after time span, 3 minutes.

is valid usage pattern ddd akka?

usually db reading operations (crud) can performed directly actor. there no need make special handling in cases. simple round-robin balance load.

as update operations (crud), can split non intersecting domains/shards. instance, operations single account should preferably processed single actor. 1 may have n independent processing actors , router routes commands 1 of them based on account.hashcode % n, instance. operations distributed between actors more or less evenly , every account processed sequentially.

p.s. slick seems descent db library akka applications.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -