SlideShare a Scribd company logo
The Newest in
Session Types
Dr. Roland Kuhn
@rolandkuhn — Akka Tech Lead
The Problem
Which problem are we trying to solve?
• reasoning about distributed programs is hard
• finding the flaws is large systems is hard
• we need better tools to
• help us design the interaction of distributed components
• help us implement said components
3
Session Types
Definition
• Session: aunitofconversation
• Session Type: thestructureofaconversation,

a sequence of interactions in a communication-centric
program model
• originally only binary sessions, multiparty sessions
introduced 2008 by Kohei Honda
• primitives are

sending,receiving,sequence,choice,recursion
• http://groups.inf.ed.ac.uk/abcd/index.html
5
Scribble
• commonly used language for defining protocols
• defines the global protocol for all participants
• verifies the safety of the global protocol
• local projection for a single participant preserves safety
• automatic generation of FSA for local runtime validation
• type discipline for local processes requires support
for expressing linearity from the host language
• where that is unavailable use dynamic validation
6
An Example
• global protocol (a asks b to calculate «x/y»):

a→b: ⟨number⟩ . a→b: ⟨number⟩ .

b→a: { ok: b→a: ⟨number⟩ . end, fail: end }
• local projection for a:

[b]!⟨number⟩ . [b]!⟨number⟩ .

[b]?{ ok: [b]?⟨number⟩ . end, fail: end }
• local projection for b:

[a]?⟨number⟩ . [a]?⟨number⟩ .

[a]!{ ok: [a]!⟨number⟩ . end, fail: end }
7
Report from the ABCD group meeting
Glasgow, Sep 16 & 17, 2015
(in random order)
Talks I didn’t quite understand
• Ornela Dharda: Comparing deadlock free session typed
processes
• showing equivalence of different encodings in π-calculus
• Garrett Morris: Substructural types with class
• how to encode linearity in Haskell
• Dimitris Kouzapas: Characteristic bisimulation for
higher-order session types and Mungo: typechecking
protocols
• lots of typing rules and derivations
9
Julian Lange: Meeting Deadlines Together
• based on Communicating Timed Automata
• the idea is to enrich protocol descriptions with
timing information in order to allow reasoning
about whether a component can meet its SLA
• written in Haskell and using Z3 for constraint
solving, checking may take a long time (minutes)
10
Bernardo Toninho: Certifying data in
multiparty session types
• Be more precise about what is exchanged in the course of a protocol
• Primary tool is the use of singleton types / dependent types
• Singleton types are scoped to entities that have seen them, identical
values are not necessarily recognized as such without global
knowledge
• Projection of the global type needs to add all required local knowledge
(proofs) so that the recipient can make sense of the message
• Proofs may be compressible by using certificates or may even be
elided
• Erasure of proofs can be done within trusted systems, passing proofs
around allows separate compilation
11
Alceste Scalas: Towards type-safe sessions in
Scala
• encoding linear channels using Promise/Future
• abstracting over it using Channel type hierarchy
(Input, Output, End) with nice syntax sugar for
receiving and sending in a type-safe fashion,
including the handling of continuations
• distribution planned via Akka Typed actors
• multiple-use will raise exceptions, but cannot reject
non-use of a channel (i.e. omitting a required action)
12
Dominic Orchard: Session types for Cloud
Haskell
• local session types are projected to Haskell types
• graded monad: tracking effects of computation and defining a
combinator for how effects are composed:

(>>=) :: m s a -> (a -> m t b) -> m (Plus m s
t) b
• parameterized monad: i, j, k are pre/post-conditions

(>>=) :: m i j a -> (a -> m j k b) -> m i k b
• general idea is to track what a process does and then compare it to
what it should do
• horrible type errors due to user having to introduce fresh names
manually
13
Y.T.: Akka Typed—Opportunities for Session
Types
• lifting Actor behavior into a monadic representation
allows effect tracking
• either at runtime, within the interpreter for the monad
• or at compile-time, if graded monads are feasible
14
Simple Ticket Counter Example (Akka Typed)
15
case class Incr(replyTo: ActorRef[Count])
case class Count(n: Int)
def ticket(n: Int): ActorAction[Incr, Behavior[Incr]] =
for {
msg <- receive[Incr]
_ <- send(msg.replyTo, Count(n)).toActor
z <- ticket(n + 1)
} yield z
val counter = Action(ticket(0)) // Behavior[Incr]
val counterRef = ActorSystem("counter", Props(counter)) // ActorSystem[Incr]
How can we forget something?
16
trait Input
case class Intro(step1: ActorRef[Step1]) extends Input
case class Step1(replyTo: ActorRef[Step1Reply])
case class Step1Reply(step2: ActorRef[Step2]) extends Input
case class Step2()
def twoSteps: ActorAction[Input, Behavior[Input]] =
for {
Intro(step1) <- receive[Input]
self <- selfRef
_ <- send(step1, Step1(self)).toActor
Step1Reply(step2) <- receive[Input]
// what prevents usage of step1 here?
_ <- send(step2, Step2()).toActor
z <- twoSteps
} yield z
Roly Perera: Multiparty compatibility without
types
• the idea is that instead of projecting a global
protocol down to local ones we piece together local
sessions into a global protocol and check that one
• this saves the duplication in “implementing the
protocol in two languages”, but requires mocking
out participants for multi-team development
• can express certain types of recursion (if decidably
unfoldable)
17
Simon Fowler: Detecting and handling errors
in Monitored Session Erlang
• Multiparty Session Actors: actors fulfill roles that they declare
• Initiate a controller actor for a session
• Invite actors to fulfill roles
• Maintain mapping between roles and PIDs
• Message sends always go through monitor processes
• Encapsulating subsessions would be nice, in particular with
different reaction to success and failure, but this could be
problematic in the presence of network partitions.
• Inviting actors into subsessions is seen as very useful, both involving
internal as well as external participants. This is equivalent to
protocol refinement.
18
Florian Weber: POP3 with Scribble, StMungo
and Mungo
• Scribble formulation of the POP3 protocol
• StMungo translates local projection of that protocol
to Mungo (annotated Java) syntax
• Mungo aims at writing normal imperative code that
is annotated and verified instead of requiring the
use of a construct like graded monad or linear types
19
Dimitrios Kouzapas: ABCD use-case repository
• https://github.com/epsrc-abcd/session-types-use-
cases
• organization of collaboration so that new tools/
languages can be applied to existing use-cases for
validation and comparison to previous solutions
• this is a good place to start looking for examples when
trying to learn things—opening issues when things are
unclear is probably a good idea :-)
• additions of industry use-cases are welcome!
20
Summary
Summary
• Session types are demonstrably implementable
and applicable to real-world internet protocols
• The ABCD group is keen on practical validation of
the approach and industry feedback
• Largest barrier is deemed to be the expression of
linearity in host languages
22
My Largest Question: Compositionality
• Given an established Session Type, can we
formulate a set of rules or restriction for refining it
(adding to it) so that existing safety properties are
preserved?
23
©Typesafe 2015 – All Rights Reserved

More Related Content

PDF
Reactive Design Patterns — J on the Beach
PDF
Reactive Streams: Handling Data-Flow the Reactive Way
PDF
Distributed systems vs compositionality
PDF
Journey into Reactive Streams and Akka Streams
PDF
Reactive Programming with Rx
PDF
Reactive Streams / Akka Streams - GeeCON Prague 2014
PPTX
Intro to Functional Programming with RxJava
PPTX
Zookeeper Architecture
Reactive Design Patterns — J on the Beach
Reactive Streams: Handling Data-Flow the Reactive Way
Distributed systems vs compositionality
Journey into Reactive Streams and Akka Streams
Reactive Programming with Rx
Reactive Streams / Akka Streams - GeeCON Prague 2014
Intro to Functional Programming with RxJava
Zookeeper Architecture

What's hot (20)

PDF
Streams, Streams Everywhere! An Introduction to Rx
PDF
Building Scalable Stateless Applications with RxJava
PPTX
Winter is coming? Not if ZooKeeper is there!
PDF
Reactive programming with RxJava
PDF
Reactive mistakes reactive nyc
PDF
Self-managed and automatically reconfigurable stream processing
PDF
Reactive programming using rx java & akka actors - pdx-scala - june 2014
PPTX
Developing distributed applications with Akka and Akka Cluster
PPTX
TDC2016SP - Trilha Node.Js
PDF
Asynchronous stream processing with Akka Streams
PDF
Practical RxJava for Android
PDF
Reactive mistakes - ScalaDays Chicago 2017
PDF
How to Think in RxJava Before Reacting
PDF
Distributed Real-Time Stream Processing: Why and How 2.0
PPTX
Reactive Programming and RxJS
PPTX
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
PDF
RxJava - introduction & design
PDF
Reactive programming with Rxjava
PDF
RxJava 2.0 介紹
PDF
Pulsar connector on flink 1.14
Streams, Streams Everywhere! An Introduction to Rx
Building Scalable Stateless Applications with RxJava
Winter is coming? Not if ZooKeeper is there!
Reactive programming with RxJava
Reactive mistakes reactive nyc
Self-managed and automatically reconfigurable stream processing
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Developing distributed applications with Akka and Akka Cluster
TDC2016SP - Trilha Node.Js
Asynchronous stream processing with Akka Streams
Practical RxJava for Android
Reactive mistakes - ScalaDays Chicago 2017
How to Think in RxJava Before Reacting
Distributed Real-Time Stream Processing: Why and How 2.0
Reactive Programming and RxJS
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
RxJava - introduction & design
Reactive programming with Rxjava
RxJava 2.0 介紹
Pulsar connector on flink 1.14
Ad

Viewers also liked (20)

PDF
Akka Typed — between Session Types and the Actor Model
PDF
Project Gålbma – Actors vs Types
PDF
Go Reactive: Blueprint for Future Applications
PDF
Relational Databases are Evolving To Support New Data Capabilities
 
PDF
Scala Abide: A lint tool for Scala
PDF
Your Code is Wrong
PDF
Puppet at Google
PPTX
PDF
IMCSummit 2015 - Day 2 IT Business Track - 4 Myths about In-Memory Databases ...
PDF
The Need for Async @ ScalaWorld
PDF
Akka cluster overview at 010dev
PDF
Delivering Meaning In Near-Real Time At High Velocity In Massive Scale with A...
PPTX
Purely Functional Data Structures in Scala
PDF
Monadic Java
PDF
Akka and AngularJS – Reactive Applications in Practice
PDF
NewSQL overview, Feb 2015
PDF
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
PPT
рататуй
 
PPT
Presentationv1
PDF
Culture at BazingaLabs
Akka Typed — between Session Types and the Actor Model
Project Gålbma – Actors vs Types
Go Reactive: Blueprint for Future Applications
Relational Databases are Evolving To Support New Data Capabilities
 
Scala Abide: A lint tool for Scala
Your Code is Wrong
Puppet at Google
IMCSummit 2015 - Day 2 IT Business Track - 4 Myths about In-Memory Databases ...
The Need for Async @ ScalaWorld
Akka cluster overview at 010dev
Delivering Meaning In Near-Real Time At High Velocity In Massive Scale with A...
Purely Functional Data Structures in Scala
Monadic Java
Akka and AngularJS – Reactive Applications in Practice
NewSQL overview, Feb 2015
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
рататуй
 
Presentationv1
Culture at BazingaLabs
Ad

Similar to The Newest in Session Types (20)

PDF
OOPSLA02 BehavioralSemantics.ppt
PDF
Principal Type Scheme for Session Types
PDF
A simple library implementation of binary sessions
PDF
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
PDF
Scala google
PDF
Oopsla02 behavioralsemantics.ppt
PDF
Google06
PDF
ETAPS03 SC.ppt
PDF
MINA2 (Apache Netty)
PDF
A Survey of Concurrency Constructs
PPTX
2018 12-kube con-ballerinacon
PPTX
Akka-demy (a.k.a. How to build stateful distributed systems) I/II
PPTX
The dark side of Akka and the remedy - bp.scala meetup
PDF
Concurrent and Distributed Applications with Akka, Java and Scala
PDF
The dark side of Akka and the remedy
PDF
Miles Sabin Introduction To Scala For Java Developers
PDF
A Brief Introduction to Scala for Java Developers
PDF
Ballerina is not Java (or Go or ..)
PPTX
2018 07-ballerina-ballerina con
PPT
Uml Omg Fundamental Certification 5
OOPSLA02 BehavioralSemantics.ppt
Principal Type Scheme for Session Types
A simple library implementation of binary sessions
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Scala google
Oopsla02 behavioralsemantics.ppt
Google06
ETAPS03 SC.ppt
MINA2 (Apache Netty)
A Survey of Concurrency Constructs
2018 12-kube con-ballerinacon
Akka-demy (a.k.a. How to build stateful distributed systems) I/II
The dark side of Akka and the remedy - bp.scala meetup
Concurrent and Distributed Applications with Akka, Java and Scala
The dark side of Akka and the remedy
Miles Sabin Introduction To Scala For Java Developers
A Brief Introduction to Scala for Java Developers
Ballerina is not Java (or Go or ..)
2018 07-ballerina-ballerina con
Uml Omg Fundamental Certification 5

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPT
Teaching material agriculture food technology
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Mushroom cultivation and it's methods.pdf
A comparative analysis of optical character recognition models for extracting...
Getting Started with Data Integration: FME Form 101
Reach Out and Touch Someone: Haptics and Empathic Computing
A comparative study of natural language inference in Swahili using monolingua...
Teaching material agriculture food technology
Univ-Connecticut-ChatGPT-Presentaion.pdf
1. Introduction to Computer Programming.pptx
Encapsulation theory and applications.pdf
A Presentation on Artificial Intelligence
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
OMC Textile Division Presentation 2021.pptx
Machine Learning_overview_presentation.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Spectral efficient network and resource selection model in 5G networks

The Newest in Session Types

  • 1. The Newest in Session Types Dr. Roland Kuhn @rolandkuhn — Akka Tech Lead
  • 3. Which problem are we trying to solve? • reasoning about distributed programs is hard • finding the flaws is large systems is hard • we need better tools to • help us design the interaction of distributed components • help us implement said components 3
  • 5. Definition • Session: aunitofconversation • Session Type: thestructureofaconversation,
 a sequence of interactions in a communication-centric program model • originally only binary sessions, multiparty sessions introduced 2008 by Kohei Honda • primitives are
 sending,receiving,sequence,choice,recursion • http://groups.inf.ed.ac.uk/abcd/index.html 5
  • 6. Scribble • commonly used language for defining protocols • defines the global protocol for all participants • verifies the safety of the global protocol • local projection for a single participant preserves safety • automatic generation of FSA for local runtime validation • type discipline for local processes requires support for expressing linearity from the host language • where that is unavailable use dynamic validation 6
  • 7. An Example • global protocol (a asks b to calculate «x/y»):
 a→b: ⟨number⟩ . a→b: ⟨number⟩ .
 b→a: { ok: b→a: ⟨number⟩ . end, fail: end } • local projection for a:
 [b]!⟨number⟩ . [b]!⟨number⟩ .
 [b]?{ ok: [b]?⟨number⟩ . end, fail: end } • local projection for b:
 [a]?⟨number⟩ . [a]?⟨number⟩ .
 [a]!{ ok: [a]!⟨number⟩ . end, fail: end } 7
  • 8. Report from the ABCD group meeting Glasgow, Sep 16 & 17, 2015 (in random order)
  • 9. Talks I didn’t quite understand • Ornela Dharda: Comparing deadlock free session typed processes • showing equivalence of different encodings in π-calculus • Garrett Morris: Substructural types with class • how to encode linearity in Haskell • Dimitris Kouzapas: Characteristic bisimulation for higher-order session types and Mungo: typechecking protocols • lots of typing rules and derivations 9
  • 10. Julian Lange: Meeting Deadlines Together • based on Communicating Timed Automata • the idea is to enrich protocol descriptions with timing information in order to allow reasoning about whether a component can meet its SLA • written in Haskell and using Z3 for constraint solving, checking may take a long time (minutes) 10
  • 11. Bernardo Toninho: Certifying data in multiparty session types • Be more precise about what is exchanged in the course of a protocol • Primary tool is the use of singleton types / dependent types • Singleton types are scoped to entities that have seen them, identical values are not necessarily recognized as such without global knowledge • Projection of the global type needs to add all required local knowledge (proofs) so that the recipient can make sense of the message • Proofs may be compressible by using certificates or may even be elided • Erasure of proofs can be done within trusted systems, passing proofs around allows separate compilation 11
  • 12. Alceste Scalas: Towards type-safe sessions in Scala • encoding linear channels using Promise/Future • abstracting over it using Channel type hierarchy (Input, Output, End) with nice syntax sugar for receiving and sending in a type-safe fashion, including the handling of continuations • distribution planned via Akka Typed actors • multiple-use will raise exceptions, but cannot reject non-use of a channel (i.e. omitting a required action) 12
  • 13. Dominic Orchard: Session types for Cloud Haskell • local session types are projected to Haskell types • graded monad: tracking effects of computation and defining a combinator for how effects are composed:
 (>>=) :: m s a -> (a -> m t b) -> m (Plus m s t) b • parameterized monad: i, j, k are pre/post-conditions
 (>>=) :: m i j a -> (a -> m j k b) -> m i k b • general idea is to track what a process does and then compare it to what it should do • horrible type errors due to user having to introduce fresh names manually 13
  • 14. Y.T.: Akka Typed—Opportunities for Session Types • lifting Actor behavior into a monadic representation allows effect tracking • either at runtime, within the interpreter for the monad • or at compile-time, if graded monads are feasible 14
  • 15. Simple Ticket Counter Example (Akka Typed) 15 case class Incr(replyTo: ActorRef[Count]) case class Count(n: Int) def ticket(n: Int): ActorAction[Incr, Behavior[Incr]] = for { msg <- receive[Incr] _ <- send(msg.replyTo, Count(n)).toActor z <- ticket(n + 1) } yield z val counter = Action(ticket(0)) // Behavior[Incr] val counterRef = ActorSystem("counter", Props(counter)) // ActorSystem[Incr]
  • 16. How can we forget something? 16 trait Input case class Intro(step1: ActorRef[Step1]) extends Input case class Step1(replyTo: ActorRef[Step1Reply]) case class Step1Reply(step2: ActorRef[Step2]) extends Input case class Step2() def twoSteps: ActorAction[Input, Behavior[Input]] = for { Intro(step1) <- receive[Input] self <- selfRef _ <- send(step1, Step1(self)).toActor Step1Reply(step2) <- receive[Input] // what prevents usage of step1 here? _ <- send(step2, Step2()).toActor z <- twoSteps } yield z
  • 17. Roly Perera: Multiparty compatibility without types • the idea is that instead of projecting a global protocol down to local ones we piece together local sessions into a global protocol and check that one • this saves the duplication in “implementing the protocol in two languages”, but requires mocking out participants for multi-team development • can express certain types of recursion (if decidably unfoldable) 17
  • 18. Simon Fowler: Detecting and handling errors in Monitored Session Erlang • Multiparty Session Actors: actors fulfill roles that they declare • Initiate a controller actor for a session • Invite actors to fulfill roles • Maintain mapping between roles and PIDs • Message sends always go through monitor processes • Encapsulating subsessions would be nice, in particular with different reaction to success and failure, but this could be problematic in the presence of network partitions. • Inviting actors into subsessions is seen as very useful, both involving internal as well as external participants. This is equivalent to protocol refinement. 18
  • 19. Florian Weber: POP3 with Scribble, StMungo and Mungo • Scribble formulation of the POP3 protocol • StMungo translates local projection of that protocol to Mungo (annotated Java) syntax • Mungo aims at writing normal imperative code that is annotated and verified instead of requiring the use of a construct like graded monad or linear types 19
  • 20. Dimitrios Kouzapas: ABCD use-case repository • https://github.com/epsrc-abcd/session-types-use- cases • organization of collaboration so that new tools/ languages can be applied to existing use-cases for validation and comparison to previous solutions • this is a good place to start looking for examples when trying to learn things—opening issues when things are unclear is probably a good idea :-) • additions of industry use-cases are welcome! 20
  • 22. Summary • Session types are demonstrably implementable and applicable to real-world internet protocols • The ABCD group is keen on practical validation of the approach and industry feedback • Largest barrier is deemed to be the expression of linearity in host languages 22
  • 23. My Largest Question: Compositionality • Given an established Session Type, can we formulate a set of rules or restriction for refining it (adding to it) so that existing safety properties are preserved? 23
  • 24. ©Typesafe 2015 – All Rights Reserved