This document discusses actors and microservices. It introduces the actor model as an approach to concurrent programming that avoids problems with shared state and locking through message passing between lightweight actors. An actor processes messages asynchronously by message type rather than by shared threads or memory. This simplifies concurrency. The document also discusses virtual actors which provide a higher abstraction level through a runtime that handles actor placement and scaling. It provides an example of a URL shortening service implemented using virtual actors compared to a traditional multithreaded approach. Finally, it discusses how the actor model can be applied to build actor-based microservices.
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
6.
7. The Actor Model
• Formalized in 1973 (Carl Hewitt)
• Concurrency by Message Passing
• Avoids problems of threading and locking
8. An Actor
• Lightweight
• Never shares state
• Communicates through asynchronous messages
• Mailbox buffers incoming messages
• Processes one message at a time
9. An Actor
• Lightweight
• Never shares state
• Communicates through asynchronous messages
• Mailbox buffers incoming messages
• Processes one message at a time
• Single threaded
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
13. Virtual Actors
• A simplified Actors implementation with a higher abstraction
level
• Introduced by Microsoft Research – Project Orleans
• A port to Java – Orbit (by EA)
14. Virtual Actors
• Goals:
• Make distributed application programming easier
• Prefer developer productivity and transparent scalability
• “A programming model and runtime for building cloud
native services”
20. A Short Example…
URL Shortener Service
The Classic way
shrt.uri
Stateless
Service
DB
Cache
Fetch from DB
Set in Cache
Expand
Return URL
Get From Cache
21. A Short Example…
URL Shortener Service
The Virtual Actor way
shrt.uri
Expand
Return URL
Virtual Actors Service
Worker URLActor (“shrt.uri”)
“URL”
DB
Fetch from DB
22. A Short Example…
URL Shortener Service
The Virtual Actor way
shrt.uri
Expand
Return URL
Virtual Actors Service
Worker URLActor (“shrt.uri”)
“URL”
23. A Short Example…
URL Shortener Service
The Virtual Actor way
shrt.uri
Expand
Return URL
Virtual Actors Service
Worker URLActor (“shrt.uri”)
“URL”
And logic!
24. 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
25. 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