$30 off During Our Annual Pro Sale. View Details »

Actors and microservices - Can Two Walk Together?

Actors and microservices - Can Two Walk Together?

The Actor Model is an alternative approach to writing concurrent software without the problems introduced by multithreaded concurrency.
“Virtual Actors” are a new development of the actor model, aimed for solving distributed concurrency issues, providing better productivity, and building cloud native scalable architecture.

With the recent trend of moving into microservices based architecture, there is some confusion about Actors, microservices, and how they fit together.

This session will introduce Actors, Virtual Actors, and how they make distributed application programming a lot simpler. We will then explore the idea of building a microservices architecture on top of Actors, how they combine, and some of the lessons learnt at Gigya doing that.

Presented at DevconTLV, March 2016

Rotem Hermon

March 22, 2016
Tweet

More Decks by Rotem Hermon

Other Decks in Programming

Transcript

  1. Actors, Microservices…
    Rotem Hermon
    @margolis20
    Can two walk
    together?

    View Slide

  2. Actors?

    View Slide

  3. Concurrency

    View Slide

  4. Multithreading

    View Slide

  5. The problem with multi-threaded concurrency
    • Shared memory and state
    • Race conditions
    • Locks and deadlocks
    • Blocking calls
    • Hard to understand and maintain
    • Not easily distributed

    View Slide

  6. View Slide

  7. The Actor Model
    • Formalized in 1973 (Carl Hewitt)
    • Concurrency by Message Passing
    • Avoids problems of threading and locking

    View Slide

  8. An Actor
    • Lightweight
    • Never shares state
    • Communicates through asynchronous messages
    • Mailbox buffers incoming messages
    • Processes one message at a time

    View Slide

  9. An Actor
    • Lightweight
    • Never shares state
    • Communicates through asynchronous messages
    • Mailbox buffers incoming messages
    • Processes one message at a time
    • Single threaded

    View Slide

  10. The Actor Model
    • Higher abstraction level
    • Simpler concurrent programming model
    • Write single-threaded code (easier to understand)
    • Concurrency and scale via actor instances
    • Maximizes CPU utilization
    • Easy to distribute

    View Slide

  11. View Slide

  12. Distributed
    Concurrency

    View Slide

  13. Distributed
    Concurrency

    View Slide

  14. Virtual Actors
    • A simplified Actors implementation with a higher abstraction
    level
    • Introduced by Microsoft Research – Project Orleans
    • A port to Java – Orbit (by EA)

    View Slide

  15. Virtual Actors
    • Goals:
    • Make distributed application programming easier
    • Prefer developer productivity and transparent scalability
    • “A programming model and runtime for building cloud
    native services”

    View Slide

  16. Virtual Actors
    • A Virtual Actor:
    always exists
    and
    never fails

    View Slide

  17. Virtual Actors
    Actor types:
    • Worker
    • An auto-scaling processing unit – multiple instances created by
    framework as needed

    View Slide

  18. Virtual Actors
    Actor types:
    • Single Activation
    • Guaranteed to have a single active instance in the cluster

    View Slide

  19. Virtual Actors
    Actor types:
    • Single Activation
    • Guaranteed to have a single active instance in the cluster
    • A Stateful application middle-tier!

    View Slide

  20. Virtual Actor Framework
    • A runtime providing virtual “actor space”, analogues to
    virtual memory
    • Handles Actor placement, activation and GC when needed
    • Balances resources across the cluster, provides elastic
    scalability

    View Slide

  21. Simplified Programming Model
    • An Actor is a class, implementing an interface with
    asynchronous methods
    • The caller of an Actor uses the actor interface via a proxy
    • Messaging is transparent and handled by the runtime.
    Programmers deal with interfaces and methods

    View Slide

  22. (Actors are actually
    Nanoservices)

    View Slide

  23. A single Actors universe?

    View Slide

  24. Back to microservices

    View Slide

  25. Actor based microservices
    Service A
    Service B
    ServiceB
    Interface
    Actor
    IMyServiceB

    View Slide

  26. Actor based microservices
    Service A
    Service B
    ServiceB
    Interface
    Actor
    IMyServiceB
    ServiceB
    HTTP
    Listener

    View Slide

  27. Actor based microservices
    Service A
    Service B
    ServiceB
    Interface
    Actor
    IMyServiceB
    ServiceB
    Client
    ServiceB
    HTTP
    Listener
    JSON over HTTP

    View Slide

  28. View Slide

  29. Thank You!
    Rotem Hermon
    @margolis20
    VP Architecture @ Gigya

    View Slide