# \[Pitch #2\] Distributed Actor Runtime

**URL:** <https://forums.swift.org/t/pitch-2-distributed-actor-runtime/55124>\
**Category:** Pitches\
**Tags:** distributed\
**Created:** [February 5, 2022, 1:09pm UTC](https://forums.swift.org/t/pitch-2-distributed-actor-runtime/55124 "2022-02-05T13:09:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktoso](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktoso/32/44526_2.png) [@ktoso](https://forums.swift.org/u/ktoso)\
**Post date:** [February 5, 2022, 1:09pm UTC](https://forums.swift.org/t/pitch-2-distributed-actor-runtime/55124/1 "2022-02-05T13:09:19Z")

</div>

Hello everyone,  
As the first part of distributed actors–[SE-0366 - Distributed Actor Isolation](https://forums.swift.org/t/accepted-se-0336-distributed-actor-isolation/54726)–was accepted recently, we proceeded on updating the second pitch to the latest state of the design and implementation.

Significant changes were made since the initial designs, most notably:

- **removal of any source generation involvement** in the design
- complete support for **generic actors and generic methods**
- **completely pluggable serialization mechanism** , which make use of SE-0366's introduction of `SerializationRequirement` and extend it with `InvocationEncoder` and `InvocationDecoder` which are able to serialize/deserialize distributed target invocations.
  - these (de-)coders are able to **read and write directly to buffers which can be used for the networking layer** of the distributed actor system, allowing for very efficient implementations; We are also able to avoid all kinds of indirections, by involving the compiler more in the synthesis of remote calls.

- the introduction of the **`remoteCall` method on DistributedActorSystem**
  - previously this was not possible because the function was not expressible in Swift; Thanks to the new SerializationRequirement, Invocation and RemoteCallTarget concepts as well as introduction of ad-hoc protocol requirement checks we were able to provide this great developer and user-experience with looks-like-normal-swift system implementations.

I'd like give huge shout-out to @kavon, @xedin who helped shape this iteration of the design and implementation. Their work on actor initializers, (distributed) method accessors and overall input on this revision of the design was invaluable. Thank you!

We will be seeking to start a review on this design as soon as the core team is available to do so; In the meantime, please review and let us know any of your questions.

We will be updating the [Swift Distributed Actors cluster implementation](http://github.com/apple/swift-distributed-actors) to support this latest runtime in the coming weeks. Feel free to track progress by watching the repository.

Thank you very much and looking forward to your feedback and questions!

* * *

- [Introduction](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#introduction)
  - [Useful links](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#useful-links)

- [Motivation](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#motivation)
  - [Example scenario](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#example-scenario)
  - [Caveat: Low-level implementation details](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#caveat-low-level-implementation-details)

- [Detailed design](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#detailed-design)
  - [The `DistributedActorSystem` protocol](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#the-distributedactorsystem-protocol)
  - [Implicit Distributed Actor Properties](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#implicit-distributed-actor-properties)
  - [Initializing Distributed Actors](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#initializing-distributed-actors)
  - [Distributed Actor initializers](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#distributed-actor-initializers)
    - [Initializing `actorSystem` and `id` properties](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#initializing-actorsystem-and-id-properties)

  - [Ready-ing Distributed Actors](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#ready-ing-distributed-actors)
    - [Ready-ing Distributed Actors, exactly once](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#ready-ing-distributed-actors-exactly-once)

  - [Resigning Distributed Actor IDs](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#resigning-distributed-actor-ids)
  - [Resolving Distributed Actors](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#resolving-distributed-actors)
  - [Invoking Distributed Methods](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#invoking-distributed-methods)
    - [Sender: Invoking a distributed method](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#sender-invoking-a-distributed-method)
    - [Sender: Serializing and Sending Invocations](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#sender-serializing-and-sending-invocations)
    - [Recipient: Receiving Invocations](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#recipient-receiving-invocations)
    - [Recipient: Deserializing incoming Invocations](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#recipient-deserializing-incoming-invocations)
    - [Recipient: Resolving the recipient actor instance](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#recipient-resolving-the-recipient-actor-instance)
    - [Recipient: The `executeDistributedTarget` method](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#recipient-the-executedistributedtarget-method)
    - [Recipient: Executing the distributed target](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#recipient-executing-the-distributed-target)
    - [Recipient: Collecting result/error from the Invocation](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#recipient-collecting-resulterror-from-the-invocation)

- [Future Work](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#future-work)
  - [Variadic generics removing the need for `remoteCallVoid`](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#variadic-generics-removing-the-need-for-remotecallvoid)
  - [Stable names and more API evolution features](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#stable-names-and-more-api-evolution-features)
  - [Resolving DistributedActor protocols](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#resolving-distributedactor-protocols)
  - [Passing parameters to assignID](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#passing-parameters-to-assignid)

- [Alternatives Considered](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#alternatives-considered)
  - [Define remoteCall as protocol requirement, and accept `[Any]` arguments](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#define-remotecall-as-protocol-requirement-and-accept-any-arguments)
  - [Constraining arguments, and return type with of `remoteCall` with `SerializationRequirement`](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#constraining-arguments-and-return-type-with-of-remotecall-with-serializationrequirement)
  - [Hardcoding the distributed runtime to make use of Codable](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#hardcoding-the-distributed-runtime-to-make-use-of-codable)

- [Acknowledgments & Prior Art](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#acknowledgments--prior-art)
- [Source compatibility](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#source-compatibility)
- [Effect on ABI stability](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#effect-on-abi-stability)
- [Effect on API resilience](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#effect-on-api-resilience)
- [Changelog](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md#changelog)

[**Complete pitch text available here**](https://github.com/ktoso/swift-evolution/blob/distributed-runtime/proposals/ssss-distributed-actor-runtime.md)

In case the text has some typos or silly mistakes, please comment [on the PR directly](https://github.com/apple/swift-evolution/pull/1498).

* * *

The previous pitch thread is here: [[Pitch] Distributed Actor Runtime - #14 by Nickolas\_Pohilets](https://forums.swift.org/t/pitch-distributed-actor-runtime/54045/14)
