# Background

Actor programming is one popular programming paradigm for distributed environments. Instead of using a typically programming language (e.g., Go) and communicating through RPC (e.g., gRPC), one can use an actor program language (e.g., Erlang) or an actor library (e.g., Ray) to write distributed programs at a higher level.  As an analogy, Go+gRPC is kind of like writing assembly, where actor programming is kind of like Object-Oriented programming for distributed environments.

You can think of Actor is Class in OO programming.  But when OO was designed, it didn't take into account the possibility of multi-threading and distributed environments.  For example, what would happen if both Object B (thread 1) and Object C (thread 2) invoke ObjectA.method1 (thread 3)?  The Actor programming model is designed with concurrent access and distributed setting as first-class citizen.   Each actor can communicate with the others ONLY by sending messages (thereby no race condition).  Furthermore, since everything is an actor (just like everything is an object in OO programming) and communicated by sending messages, an actor can be located and moved to different physical places easily (e.g,. local server, to the cloud).

In this lab, we will implement a simple distributed chatting application base on Actor model with Ray, a distributed execution framework.&#x20;

We will implement 2 types of Actor, `UserActor` and `ChatRoomActor`.&#x20;

One `UserActor` is created per user. It is responsible to send/receive chats to/from the `ChatRoomActor`.  `ChatRoomActor` broadcasts the chats it received to all `UserActors`.

In this lab, we will demonstrate how good Actor programming fits a distributed environment, especially the cloud environment where it can automatically scale out when the workload (e.g., the number of users in a chatroom) increases.

![](https://documents.lucid.app/documents/702c254a-a8cc-4e42-b6a2-b2fdd7116db0/pages/0_0?a=654\&x=123\&y=15\&w=1694\&h=550\&store=1\&accept=image%2F*\&auth=LCA%2028c5bd36660c53532e9a47dac343eff6b18fd678-ts%3D1614618662)
