scala - Event based design - Futures, Promises vs Akka Persistence -
scala - Event based design - Futures, Promises vs Akka Persistence -
i have multiple utilize cases require predefined events fired based on user actions.
e.g. let's when newuser
created in application, it'll have phone call createuserinworkflowsystem
, fireemailtotheuser
asynchronously. there many other business cases of nature events predefined based on usecase. can utilize promises/futures model these events below
if 'newuser' phone call `createuserinworkflowsystem` (which future based api) phone call `fireemailtotheuser` (which future based api) if 'fileimport' phone call `api3` (which future based call) phone call `api4` (which future based call)
all future
calls have log failures somewhere failed calls can retried etc. note newuser
phone call won't waiting futures
(events per say) complete.
that using plain futures/promises
apis. thinking akka persistence appropriate fit here , blocking calls can still run futures
. akka persistence, handling failure easy provides out of box etc. understand akka persistence still in experimental stage doesn't seem big concern typesafe keeps these new frameworks experimental state before promoting future release etc. (same true macros). given these requirements think futures/promises
or akka persistence improve fit here?
this opinion based question - not best type inquire on so. anyway, trying answer.
it depends more comfortable , requirements are. need scale scheme later beyond single jvm - utilize akka. want maintain more simple - utilize futures.
if utilize futures can store state , actions execute in job queue/db. it's quite reasonable.
if utilize akka persistence help persistence. akka help perform supervison, recovery , retries easier. if createuserinworkflowsystem
action fails result propagated supervising actor restarts failed actor , makes retry n times. if supervising actor fails supervisor right thing, or whole app crash good. futures have implement mechanism , create sure application can crash when needed.
if have independent actions futures , actors sound same. if have chain actions , compose them, using futures more natural thing do: for comprehensions, etc. in akka have wait message , based on type of message perform next action.
try mock simple implementation using both , compare like/dislike given particular application requirements. overall, both choices good, i'm leaning towards actors in case.
scala akka akka-persistence
Comments
Post a Comment