Choreographic programming (CP) is an emerging paradigm for programming distributed applications that run on multiple nodes. In CP, instead of implementing individual programs for each node, the programmer writes one, unified program, called a choreography, that is then transformed to individual programs for each node via a compilation step called endpoint projection (EPP). While CP languages have existed for over a decade, library-level CP — in which choreographies are expressed as programs in an existing host language, and choreographic language constructs and endpoint projection are provided entirely by a host-language library — is in its infancy. Library-level CP has the potential to improve the accessibility and practicality of CP by meeting programmers where they are, in their programming language of choice, with access to that language’s ecosystem, however, the existing implementation approaches have portability, efficiency, and practicality drawbacks that hinder its adoption.
This thesis aims to advance the state of the art of library-level CP by proposing new implementation techniques: endpoint projection as dependency injection (EPP-asDI), and choreographic enclaves. EPP-as-DI is a language-agnostic technique for implementing EPP at the library level. Unlike existing library-level approaches, EPP-as-DI asks little from the host language — support for higher-order functions is all that is required — making it usable in a wide variety of host languages. Choreographic enclaves are a language feature that lets the programmer define sub-choreographies within a larger choreography. Within an enclave, “knowledge of choice” is propagated only among the enclave participants, enabling the seamless use of the host language’s conditional constructs while addressing the efficiency limitations of existing library-level implementations of choreographic conditionals. This thesis presents ChoRus and Choreography.ts, two library-level CP implementations for Rust and TypeScript, respectively, that use EPP-as-DI and choreographic enclaves. We discuss how EPP-as-DI and choreographic enclaves are implemented in these two languages, and evaluate the usability and performance through two case studies and performance benchmarks.