Actors

Description

Actors are a way we encapsulate non-trivial business logic at Wunder, especially complex mutations. Actors may be responsible for something simple like changing the state of an object under certain conditions, or something that has many steps like disbursing funds to a borrower.

They all provide the same interface and mechanisms to handle different failure and success cases. We often group similar actors together in directories. For example, in app/actors/borrower/disbursement we have several different actors like Create and Initiate that perform operations on disbursements.

The primary benefits include:

  • Encapsulation
  • Smaller models/controllers by moving complexity out
  • Consistent interface
  • Built in handling for failure cases

Technology Status at Wunder

Adopt. Actors have been an excellent way for us to neatly encapsulate business concepts/processes in a standardized way.

Notes/Resources

For complex operations, we should use an Actor. For fundamentally simple operations, we should avoid over-engineering and fall back to Rails norms.