SlideShare a Scribd company logo
1 of 74
Download to read offline
Tutorial
SummerSOC; June 22, 2019
Sanjiva Weerawarana, sanjiva@weerawarana.org
Kishanthan Thangarajah, kishanthan@wso2.com
Prerequisites
● Download:
○ Ballerina 0.991.0 from https://ballerina.io
○ Visual Studio Code
○ Optional: Docker Desktop
● Clone GitHub repo: https://github.com/Kishanthan/SummerSOC-2019
Agenda
● Language introduction
● Type system
○ Code: Type system code examples (types directory)
● Sequence diagram concepts & concurrency
○ Code: Concurrency examples (concurrency directory)
● Networking
○ Code: Networking protocol examples (http, http2, websockets, grpc, kafka, rabbitmq directories)
○ Code: SaaS connector examples (gsheets, twitter directories)
● I/O
○ Code: IO examples (io directory)
● Security
○ Security examples (security directory)
● Static & streaming data, and querying
○ Code: Data examples (database, experimental/{tables,streams} directories)
● Transactions
○ Code: Transactions examples (experimental/transactions directory)
● Config, packaging and deployment
○ Code: Deployment examples (docker, kubernetes directories)
Part 1: Language introduction
“A programming language for network
distributed applications”
“Programming language”
● Not a DSL
● Full programming language with rich set of general purpose features
● General purpose features are optimized for “network distributed applications”
“network distributed”
● Almost all existing programming languages designed for a world where the
normal case is to integrate components running on one machine
● In the cloud world, the normal way for a program to interact with its
environment is over the network
“applications”
● Not a systems-level programming language
● Easy to write and modify is more important than squeezing the ultimate
compute performance
● Suitable for application programmers
Design principles
● Works for Mort
● Familiar
● Pragmatic
○ not a research language
● Readability
● Design language together with platform
Language vs platform
● Language
○ language means what’s defined in the language spec
○ includes tiny “lang library”
● Platform
○ language
○ standard library
○ Ballerina central
○ project structure, packerina
○ testing, testerina
○ documentation, docerina
○ etc.
What makes Ballerina unique as a
programming language?
Two features that work together
● Providing and consuming services
○ first-class language concepts with their own syntax and semantics, not a library
○ inherently concurrent
● Sequence diagrams
○ graphical view of most fundamental aspect of the semantics of a network distributed
application
○ sequence diagram view only possible because syntax and semantics of the language were
designed to enable it
○ higher-level concurrency abstraction
Ballerina is not object-oriented
● Object means data+code
● OO is wrong model for network distributed applications
● Network transparency doesn’t work
● Don’t want to send code over the network
● Serialization/deserialization of objects is not sending code
○ requires tight coupling between sender and receiver
● Can be a challenge for programmers with strongly OO background
● Ballerina does provide objects for when you really need data+code combo
Typing: strong vs static vs dynamic
● Strong typing means you do not expose the raw memory of values
○ All modern, non-systems languages are strong. Not interesting!
● Static typing means that you check types at compile time
● Dynamic typing means that you check types at run time
● Typing spectrum
○ To what extent are things checked at run-time vs compile-time?
○ How complex are the things that your type system can say?
● Too static leads to inflexibility and/or complexity
● Too dynamic means unreliable and poor IDE experience
● Ballerina has chosen pragmatic point on spectrum
Type system vs schema
● Type system describes values occurring during program execution
● Schema describes messages exchanged between programs
● Type system and schema are usually completely unrelated
● Data binding converts between the two
● Creates a lot of friction for applications that exchange messages
Ballerina’s type system also works as a schema
● Key features
○ Describes shape of a value - structural types
○ Types are just sets of values - semantic subtyping
○ Allows for choice of A or B - untagged unions
○ Extensibility - open records
● Data binding is just a type cast
○ Mutability complicates things a bit
● Most similar to TypeScript
Data structures
● “It is better to have 100 functions operate on one data structure than to have
10 functions operate on 10 data structures.” - Alan J. Perlis
● Ballerina has two fundamental data structures
○ lists: ordered list
○ mappings: mappings from strings to values
● Exact match for JSON
● Two ways to type mappings
○ records
○ maps
● Two ways to type lists
○ tuples
○ arrays
Error handling
● Errors are normal part of network programming (one reason why "network
transparent" does not work)
● Errors handled as part of normal control flow
● Error is a separate data type
● Possibility of errors described by type system in same way as rest of the
language
● Leverages untagged unions
Relationship with Java
● First implementation runs on JVM
● Not a JVM language
○ semantics not influenced by what JVM happens to do
● Designed to be language with multiple implementations
○ Language defined by spec not by implementation
Relationship to open source
● “Open source” is something that applies to code not documentation
● Saying a language is open source makes sense only for a language that is
defined by its implementation
● Misleading to say: “Ballerina language is open source”
● Ballerina spec is licensed under Creative Commons, no derivatives license
● jBallerina is open source under Apache 2.0
● Should say: “jBallerina is an open source implementation of the Ballerina
language”
Language versions
● Language version different from implementation version
○ required to support multiple implementations
○ language version = language spec version
● Language version naming scheme 20xyRn
● 2019 plan
○ 2019R1 - done
○ 2019R2 - end of June; design freeze for jBallerina 1.0
○ 2019R3 - improved spec to coordinate with release for jBallerina 1.0
○ 2019R4 - features that didn’t quite make it into R2/jBallerina 1.0
○ 2019Rn - TBD
Language stability
● Consists of
○ base stability level
○ parts with less than base stability level
● Base stability level for 2019R3
○ stable
○ there will be bugs
○ there will be new language keywords
● Parts with less than base stability
○ Clearly marked in spec
○ XML
○ Tables
● Platform versions everything
Stabilisation plan
● 2019
○ XML
○ Tables
■ language-integrated query
● 2020
○ Streaming query
○ Transactions
Language design process
● Spec maintained in XHTML in GitHub repository
https://github.com/ballerina-platform/ballerina-spec
● Most design work now happens via issues on GitHub
○ Supplemented by video conferencing
● Best way to provide input or ask a question is to create an issue
○ Please don’t mix different points in a single issue
We are using Ballerina 0.991.0
● Work in progress towards supporting 2019R2
● Some old syntax still there
● Many things still being implemented
Part 2: Type system
Values
● Values are the universe of things that all Ballerina programs operate on
● 3 kinds of values
○ simple values, like booleans and floating point numbers, which are not constructed from other
values
○ structured values, like mappings and lists, which create structures from other values
○ behavioral values, like functions, which allow parts of Ballerina programs to be handled in a
uniform way with other values
Shape and type
● Shape of a value: focus on structure of the value
○ abstracts value
○ for simple values, shape and value are the same
○ for structured and behavioral values, shape ignores storage location and mutability
■ e.g.: record { int a; string b; } and record { string b; int a; } have same shape
● Type
○ set of shapes
○ same shape can be in many sets
● Type descriptor
○ describes a type (membership test for the set)
Subtyping
● Subtype means a subset of shapes
● “Semantic subtyping”
Time for code
Part 3: Sequence diagrams &
concurrency
Sequence diagrams
● Natural way to represent and explain concurrency
○ but not used to program concurrency
● Ballerina concurrency model is built on sequence diagrams
○ every Ballerina program is a collection of sequence diagrams
○ diagram is the code, not a picture of the code
Sequence diagrams
● Many sequence diagrams, one per unit of work or collapsed to one
● Each actor / line is a sequence flow of logic
○ graphically a flow chart
● Naturally concurrent – just add parallel actors
● Active actors (code you write) and passive actors (external participants:
network services)
● Not meant to be used for low-code / no-code or by non-programmers
○ meant to make it easier to understand complex distributed interactions
Easy concurrency
● Every executable entity (function, method, resource) is a collection of workers
○ default worker
○ named workers
● Each worker is a independent execution context
● All workers of a function execute concurrently when the function is called
Strands
● Strands are independent execution stacks
○ will be scheduled into a thread
○ (not a thread because of it offers a blocking programming model by scheduling to a thread)
○ represented as a future
● Function calls within a strand are regular stack based invocation
○ default worker of a called function runs in the same strand as the calling worker
● Concurrency is across strands
○ communication between workers only, not worker to/from future
○ (to prevent deadlocks)
Worker to worker communication
● Via anonymous channels, (non-)blocking for send, blocking for receive
● Error and panic propagation
● Interaction patterns and deadlock prevention via session types
isig :=
type-descriptor -> // send a message of this type
| type-descriptor <- // receive a message of this type
| isig , isig // sequence
| isig | isig // choice
| isig * // repeat zero or more
| ( isig ) // group
Concurrency control
● Concurrency reality for business use cases and cloud native computing
○ small number of actual cores
● Lock construct (work in progress)
○ implements two phase locking
● Immutable values
○ constants
○ frozen copies
● More work TBD to provide better concurrency safety
○ Rust: ownership types
○ Swift: uniqueness types
○ Software transactional memory
Time for code
Part 4: Networking
Introduction
● Most languages treat network interactions as just communications over
another kind of I/O stream
○ Based on Berkeley socket library
● Ballerina models network interactions as a connection + interaction protocol
at language level
Concepts
● Endpoints
● Connectors
● Listeners
● Services
Endpoints
● Endpoints represent network termination points for incoming network
interactions or outgoing network interactions plus set of typed interactions that
are allowed
● Ingress vs. egress endpoints
● Egress endpoints represent remote systems
○ offers a set of actions for interaction with them
● Ingress endpoints are network entry points to a Ballerina runtime via a
registered service
○ calls are delivered to a particular resource in a service
○ offers incoming endpoint list of actions to reply/message
● Modeled as an actor in sequence diagram
Connectors
● Client objects
○ objects with some methods that are marked as “remote”
● Remote methods are network interactions
● Allows a “stub” to wrap another “stub” and propagate network awareness
Listeners
● Listeners open network entry points to a Ballerina program
● Dispatch incoming requests to one or more services based on some
listener-specific criteria
Services
● Behavioral value
● Service is a collection of resource functions and regular functions
● Resource functions are entry points to which incoming network requests are
dispatched
○ no return value - need to send responses explicitly via incoming connection reference
Time for code
Part 5: I/O
I/O system architecture
I/O
● Blocking programming model with non-blocking performance
○ blocks worker (and therefore strand), not thread
● Comprehensive I/O package with flexibility to extend
○ bytes -> character -> record
Time for code
Part 6: Security
Security
● Goal is to make programs secure by default
○ force programmer to think about security
○ make it easy to establish security
● Security means
○ not trusting data from the network
○ knowing who is calling you (authentication)
○ checking authority to execute (authorization)
Taint checking
● Data from untrusted sources is considered “tainted”
● Touching tainted data taints you
○ propagates across function calls
● Untainting requires explicit programmer action to sanitize
● Done via annotations
○ Current version has untaint operator; will be changing
Authentication
● Not in language per se
● All network connectors & listeners support appropriate protocols
● Common concept of principal
Authorization
● Permission model based on scopes
○ borrowed from OAuth
Time for code
Part 7: Data & querying
(WIP)
Kinds of data
● Tabular data
○ table data type
● Graph data
○ maps & records
● Streaming data
○ stream data type
Tables & SQL-like querying
● First class data type in language
○ collection of records
○ keys
● Integrated query syntax to query tables directly
○ Similar to C# LINQ
● Future: mirroring tables from databases, mapping to network tables, CSV
Graph data
● Maps and records
● Exploring GraphQL
Streaming data
● stream type
○ distribute events to listeners
● Streaming queries
○ permanently block worker and execute streaming SQL like queries
Time for code
Part 8: Transactions
Transactions
● Goal is to make correct transactional programming natural and easy
● Support for
○ local & distributed transactions
○ 2PC and compensation
● No external transaction coordinator required
Local transactions
● Language construct for transactions
transaction {
} onretry {
} committed {
} aborted {
}
Distributed transactions
● New Ballerina microtransaction protocol
○ designed by Frank Leymann
● Goal is to make microservice transactions work smoothly
○ Initiator creates a coordinator
○ Participants have transaction infected to them transparently
○ Works OOTB for Ballerina distributed transactions and with sidecar for others
● Compensation
● WIP
Time for code
Part 9: Config & deployment
Configuration
● Applications need to externalize configuration
● Two layers
○ config API
○ language support
● Language support for configuration
○ mark module level variables/attributes as configurable
○ externally refer to those and provide values
○ language startup system will read and population values before user code starts
○ (inspired by X Window System config model)
Deployment
● Gone are the days of compiling and running programs
● Now
○ build
○ create Docker image
○ write YAML files
○ deploy
○ start
● Programmer is usually out of the loop on all of these
● Ballerina compiler supports extensibility for compilation process to include
additional functions into compilation process
Time for code
Summary
Summary
● Ballerina is a programming language for network distributed applications
○ goal is to make writing such applications at least 3-5x faster, better, cheaper
● Brings fundamental concepts of networking, concurrency, data, security,
deployment all together in an approach that offers both equivalent textual and
graphical syntaxes
● Current implementation uses JVM but native compilation will come in 2020
● Language still evolving but stable core ready to go
● Already used in production for commercial products
○ jBallerina 1.0 in July/August

More Related Content

Similar to Ballerina Tutorial @ SummerSOC 2019

[Open Source Summit 2019] Microservices with Ballerina
[Open Source Summit 2019] Microservices with Ballerina[Open Source Summit 2019] Microservices with Ballerina
[Open Source Summit 2019] Microservices with BallerinaWSO2
 
Substrait Overview.pdf
Substrait Overview.pdfSubstrait Overview.pdf
Substrait Overview.pdfRinat Abdullin
 
[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...
[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...
[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...WSO2
 
Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...
Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...
Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...Yenlo
 
Python Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development EnvironmentPython Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development EnvironmentPython Devloper
 
From class to architecture
From class to architectureFrom class to architecture
From class to architectureMarcin Hawraniak
 
Introduction to functional programming, with Elixir
Introduction to functional programming,  with ElixirIntroduction to functional programming,  with Elixir
Introduction to functional programming, with Elixirkirandanduprolu
 
Open Chemistry, JupyterLab and data: Reproducible quantum chemistry
Open Chemistry, JupyterLab and data: Reproducible quantum chemistryOpen Chemistry, JupyterLab and data: Reproducible quantum chemistry
Open Chemistry, JupyterLab and data: Reproducible quantum chemistryMarcus Hanwell
 
Software development, mobile platforms, cloud services - Lean Development and...
Software development, mobile platforms, cloud services - Lean Development and...Software development, mobile platforms, cloud services - Lean Development and...
Software development, mobile platforms, cloud services - Lean Development and...Francesco Mapelli
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBhalaji Nagarajan
 
[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...
[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...
[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...Anupama Piyumali Pathirage
 
The GO programming language
The GO programming languageThe GO programming language
The GO programming languageMarco Sabatini
 
[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...
[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...
[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...Anupama Piyumali Pathirage
 
Software Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale AutomationSoftware Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale AutomationHao Xu
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 

Similar to Ballerina Tutorial @ SummerSOC 2019 (20)

[Open Source Summit 2019] Microservices with Ballerina
[Open Source Summit 2019] Microservices with Ballerina[Open Source Summit 2019] Microservices with Ballerina
[Open Source Summit 2019] Microservices with Ballerina
 
Substrait Overview.pdf
Substrait Overview.pdfSubstrait Overview.pdf
Substrait Overview.pdf
 
[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...
[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...
[WSO2 Integration Summit San Francisco 2019] Ballerina - Cloud Native Middlew...
 
Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...
Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...
Ballerina cloud native middleware as a programming language | Yenlo - WSO2 In...
 
Python Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development EnvironmentPython Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development Environment
 
Go at uber
Go at uberGo at uber
Go at uber
 
From class to architecture
From class to architectureFrom class to architecture
From class to architecture
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to functional programming, with Elixir
Introduction to functional programming,  with ElixirIntroduction to functional programming,  with Elixir
Introduction to functional programming, with Elixir
 
Open Chemistry, JupyterLab and data: Reproducible quantum chemistry
Open Chemistry, JupyterLab and data: Reproducible quantum chemistryOpen Chemistry, JupyterLab and data: Reproducible quantum chemistry
Open Chemistry, JupyterLab and data: Reproducible quantum chemistry
 
Software development, mobile platforms, cloud services - Lean Development and...
Software development, mobile platforms, cloud services - Lean Development and...Software development, mobile platforms, cloud services - Lean Development and...
Software development, mobile platforms, cloud services - Lean Development and...
 
Anything-to-Graph
Anything-to-GraphAnything-to-Graph
Anything-to-Graph
 
Towards Data Operations
Towards Data OperationsTowards Data Operations
Towards Data Operations
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
 
C++
C++C++
C++
 
[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...
[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...
[Women in Tech Global Conference - 2022]Cloud-Native Middleware as a Programm...
 
The GO programming language
The GO programming languageThe GO programming language
The GO programming language
 
[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...
[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...
[DeveloperWeek Cloud - 2022]Programming language Designed for Cloud Native Ap...
 
Software Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale AutomationSoftware Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale Automation
 
Python for katana
Python for katanaPython for katana
Python for katana
 

More from kshanth2101

What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrencykshanth2101
 
Evolution of Application Development
Evolution of Application DevelopmentEvolution of Application Development
Evolution of Application Developmentkshanth2101
 
WSO2Con Europe 2016 - Extension Points of Carbon Architecture
WSO2Con Europe 2016 - Extension Points of Carbon ArchitectureWSO2Con Europe 2016 - Extension Points of Carbon Architecture
WSO2Con Europe 2016 - Extension Points of Carbon Architecturekshanth2101
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrencykshanth2101
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1kshanth2101
 
Introduction to OSGi - Part-2
Introduction to OSGi - Part-2Introduction to OSGi - Part-2
Introduction to OSGi - Part-2kshanth2101
 

More from kshanth2101 (6)

What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrency
 
Evolution of Application Development
Evolution of Application DevelopmentEvolution of Application Development
Evolution of Application Development
 
WSO2Con Europe 2016 - Extension Points of Carbon Architecture
WSO2Con Europe 2016 - Extension Points of Carbon ArchitectureWSO2Con Europe 2016 - Extension Points of Carbon Architecture
WSO2Con Europe 2016 - Extension Points of Carbon Architecture
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrency
 
Introduction to OSGi - Part-1
Introduction to OSGi - Part-1Introduction to OSGi - Part-1
Introduction to OSGi - Part-1
 
Introduction to OSGi - Part-2
Introduction to OSGi - Part-2Introduction to OSGi - Part-2
Introduction to OSGi - Part-2
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 

Recently uploaded (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 

Ballerina Tutorial @ SummerSOC 2019

  • 1. Tutorial SummerSOC; June 22, 2019 Sanjiva Weerawarana, sanjiva@weerawarana.org Kishanthan Thangarajah, kishanthan@wso2.com
  • 2. Prerequisites ● Download: ○ Ballerina 0.991.0 from https://ballerina.io ○ Visual Studio Code ○ Optional: Docker Desktop ● Clone GitHub repo: https://github.com/Kishanthan/SummerSOC-2019
  • 3. Agenda ● Language introduction ● Type system ○ Code: Type system code examples (types directory) ● Sequence diagram concepts & concurrency ○ Code: Concurrency examples (concurrency directory) ● Networking ○ Code: Networking protocol examples (http, http2, websockets, grpc, kafka, rabbitmq directories) ○ Code: SaaS connector examples (gsheets, twitter directories) ● I/O ○ Code: IO examples (io directory) ● Security ○ Security examples (security directory) ● Static & streaming data, and querying ○ Code: Data examples (database, experimental/{tables,streams} directories) ● Transactions ○ Code: Transactions examples (experimental/transactions directory) ● Config, packaging and deployment ○ Code: Deployment examples (docker, kubernetes directories)
  • 4. Part 1: Language introduction
  • 5. “A programming language for network distributed applications”
  • 6. “Programming language” ● Not a DSL ● Full programming language with rich set of general purpose features ● General purpose features are optimized for “network distributed applications”
  • 7. “network distributed” ● Almost all existing programming languages designed for a world where the normal case is to integrate components running on one machine ● In the cloud world, the normal way for a program to interact with its environment is over the network
  • 8. “applications” ● Not a systems-level programming language ● Easy to write and modify is more important than squeezing the ultimate compute performance ● Suitable for application programmers
  • 9. Design principles ● Works for Mort ● Familiar ● Pragmatic ○ not a research language ● Readability ● Design language together with platform
  • 10. Language vs platform ● Language ○ language means what’s defined in the language spec ○ includes tiny “lang library” ● Platform ○ language ○ standard library ○ Ballerina central ○ project structure, packerina ○ testing, testerina ○ documentation, docerina ○ etc.
  • 11. What makes Ballerina unique as a programming language?
  • 12. Two features that work together ● Providing and consuming services ○ first-class language concepts with their own syntax and semantics, not a library ○ inherently concurrent ● Sequence diagrams ○ graphical view of most fundamental aspect of the semantics of a network distributed application ○ sequence diagram view only possible because syntax and semantics of the language were designed to enable it ○ higher-level concurrency abstraction
  • 13. Ballerina is not object-oriented ● Object means data+code ● OO is wrong model for network distributed applications ● Network transparency doesn’t work ● Don’t want to send code over the network ● Serialization/deserialization of objects is not sending code ○ requires tight coupling between sender and receiver ● Can be a challenge for programmers with strongly OO background ● Ballerina does provide objects for when you really need data+code combo
  • 14. Typing: strong vs static vs dynamic ● Strong typing means you do not expose the raw memory of values ○ All modern, non-systems languages are strong. Not interesting! ● Static typing means that you check types at compile time ● Dynamic typing means that you check types at run time ● Typing spectrum ○ To what extent are things checked at run-time vs compile-time? ○ How complex are the things that your type system can say? ● Too static leads to inflexibility and/or complexity ● Too dynamic means unreliable and poor IDE experience ● Ballerina has chosen pragmatic point on spectrum
  • 15. Type system vs schema ● Type system describes values occurring during program execution ● Schema describes messages exchanged between programs ● Type system and schema are usually completely unrelated ● Data binding converts between the two ● Creates a lot of friction for applications that exchange messages
  • 16. Ballerina’s type system also works as a schema ● Key features ○ Describes shape of a value - structural types ○ Types are just sets of values - semantic subtyping ○ Allows for choice of A or B - untagged unions ○ Extensibility - open records ● Data binding is just a type cast ○ Mutability complicates things a bit ● Most similar to TypeScript
  • 17. Data structures ● “It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures.” - Alan J. Perlis ● Ballerina has two fundamental data structures ○ lists: ordered list ○ mappings: mappings from strings to values ● Exact match for JSON ● Two ways to type mappings ○ records ○ maps ● Two ways to type lists ○ tuples ○ arrays
  • 18. Error handling ● Errors are normal part of network programming (one reason why "network transparent" does not work) ● Errors handled as part of normal control flow ● Error is a separate data type ● Possibility of errors described by type system in same way as rest of the language ● Leverages untagged unions
  • 19. Relationship with Java ● First implementation runs on JVM ● Not a JVM language ○ semantics not influenced by what JVM happens to do ● Designed to be language with multiple implementations ○ Language defined by spec not by implementation
  • 20. Relationship to open source ● “Open source” is something that applies to code not documentation ● Saying a language is open source makes sense only for a language that is defined by its implementation ● Misleading to say: “Ballerina language is open source” ● Ballerina spec is licensed under Creative Commons, no derivatives license ● jBallerina is open source under Apache 2.0 ● Should say: “jBallerina is an open source implementation of the Ballerina language”
  • 21. Language versions ● Language version different from implementation version ○ required to support multiple implementations ○ language version = language spec version ● Language version naming scheme 20xyRn ● 2019 plan ○ 2019R1 - done ○ 2019R2 - end of June; design freeze for jBallerina 1.0 ○ 2019R3 - improved spec to coordinate with release for jBallerina 1.0 ○ 2019R4 - features that didn’t quite make it into R2/jBallerina 1.0 ○ 2019Rn - TBD
  • 22. Language stability ● Consists of ○ base stability level ○ parts with less than base stability level ● Base stability level for 2019R3 ○ stable ○ there will be bugs ○ there will be new language keywords ● Parts with less than base stability ○ Clearly marked in spec ○ XML ○ Tables ● Platform versions everything
  • 23. Stabilisation plan ● 2019 ○ XML ○ Tables ■ language-integrated query ● 2020 ○ Streaming query ○ Transactions
  • 24. Language design process ● Spec maintained in XHTML in GitHub repository https://github.com/ballerina-platform/ballerina-spec ● Most design work now happens via issues on GitHub ○ Supplemented by video conferencing ● Best way to provide input or ask a question is to create an issue ○ Please don’t mix different points in a single issue
  • 25. We are using Ballerina 0.991.0 ● Work in progress towards supporting 2019R2 ● Some old syntax still there ● Many things still being implemented
  • 26. Part 2: Type system
  • 27. Values ● Values are the universe of things that all Ballerina programs operate on ● 3 kinds of values ○ simple values, like booleans and floating point numbers, which are not constructed from other values ○ structured values, like mappings and lists, which create structures from other values ○ behavioral values, like functions, which allow parts of Ballerina programs to be handled in a uniform way with other values
  • 28. Shape and type ● Shape of a value: focus on structure of the value ○ abstracts value ○ for simple values, shape and value are the same ○ for structured and behavioral values, shape ignores storage location and mutability ■ e.g.: record { int a; string b; } and record { string b; int a; } have same shape ● Type ○ set of shapes ○ same shape can be in many sets ● Type descriptor ○ describes a type (membership test for the set)
  • 29. Subtyping ● Subtype means a subset of shapes ● “Semantic subtyping”
  • 30.
  • 32. Part 3: Sequence diagrams & concurrency
  • 33. Sequence diagrams ● Natural way to represent and explain concurrency ○ but not used to program concurrency ● Ballerina concurrency model is built on sequence diagrams ○ every Ballerina program is a collection of sequence diagrams ○ diagram is the code, not a picture of the code
  • 34. Sequence diagrams ● Many sequence diagrams, one per unit of work or collapsed to one ● Each actor / line is a sequence flow of logic ○ graphically a flow chart ● Naturally concurrent – just add parallel actors ● Active actors (code you write) and passive actors (external participants: network services) ● Not meant to be used for low-code / no-code or by non-programmers ○ meant to make it easier to understand complex distributed interactions
  • 35. Easy concurrency ● Every executable entity (function, method, resource) is a collection of workers ○ default worker ○ named workers ● Each worker is a independent execution context ● All workers of a function execute concurrently when the function is called
  • 36. Strands ● Strands are independent execution stacks ○ will be scheduled into a thread ○ (not a thread because of it offers a blocking programming model by scheduling to a thread) ○ represented as a future ● Function calls within a strand are regular stack based invocation ○ default worker of a called function runs in the same strand as the calling worker ● Concurrency is across strands ○ communication between workers only, not worker to/from future ○ (to prevent deadlocks)
  • 37. Worker to worker communication ● Via anonymous channels, (non-)blocking for send, blocking for receive ● Error and panic propagation ● Interaction patterns and deadlock prevention via session types isig := type-descriptor -> // send a message of this type | type-descriptor <- // receive a message of this type | isig , isig // sequence | isig | isig // choice | isig * // repeat zero or more | ( isig ) // group
  • 38. Concurrency control ● Concurrency reality for business use cases and cloud native computing ○ small number of actual cores ● Lock construct (work in progress) ○ implements two phase locking ● Immutable values ○ constants ○ frozen copies ● More work TBD to provide better concurrency safety ○ Rust: ownership types ○ Swift: uniqueness types ○ Software transactional memory
  • 41. Introduction ● Most languages treat network interactions as just communications over another kind of I/O stream ○ Based on Berkeley socket library ● Ballerina models network interactions as a connection + interaction protocol at language level
  • 43. Endpoints ● Endpoints represent network termination points for incoming network interactions or outgoing network interactions plus set of typed interactions that are allowed ● Ingress vs. egress endpoints ● Egress endpoints represent remote systems ○ offers a set of actions for interaction with them ● Ingress endpoints are network entry points to a Ballerina runtime via a registered service ○ calls are delivered to a particular resource in a service ○ offers incoming endpoint list of actions to reply/message ● Modeled as an actor in sequence diagram
  • 44. Connectors ● Client objects ○ objects with some methods that are marked as “remote” ● Remote methods are network interactions ● Allows a “stub” to wrap another “stub” and propagate network awareness
  • 45. Listeners ● Listeners open network entry points to a Ballerina program ● Dispatch incoming requests to one or more services based on some listener-specific criteria
  • 46. Services ● Behavioral value ● Service is a collection of resource functions and regular functions ● Resource functions are entry points to which incoming network requests are dispatched ○ no return value - need to send responses explicitly via incoming connection reference
  • 50. I/O ● Blocking programming model with non-blocking performance ○ blocks worker (and therefore strand), not thread ● Comprehensive I/O package with flexibility to extend ○ bytes -> character -> record
  • 53. Security ● Goal is to make programs secure by default ○ force programmer to think about security ○ make it easy to establish security ● Security means ○ not trusting data from the network ○ knowing who is calling you (authentication) ○ checking authority to execute (authorization)
  • 54. Taint checking ● Data from untrusted sources is considered “tainted” ● Touching tainted data taints you ○ propagates across function calls ● Untainting requires explicit programmer action to sanitize ● Done via annotations ○ Current version has untaint operator; will be changing
  • 55. Authentication ● Not in language per se ● All network connectors & listeners support appropriate protocols ● Common concept of principal
  • 56. Authorization ● Permission model based on scopes ○ borrowed from OAuth
  • 58. Part 7: Data & querying (WIP)
  • 59. Kinds of data ● Tabular data ○ table data type ● Graph data ○ maps & records ● Streaming data ○ stream data type
  • 60. Tables & SQL-like querying ● First class data type in language ○ collection of records ○ keys ● Integrated query syntax to query tables directly ○ Similar to C# LINQ ● Future: mirroring tables from databases, mapping to network tables, CSV
  • 61. Graph data ● Maps and records ● Exploring GraphQL
  • 62. Streaming data ● stream type ○ distribute events to listeners ● Streaming queries ○ permanently block worker and execute streaming SQL like queries
  • 65. Transactions ● Goal is to make correct transactional programming natural and easy ● Support for ○ local & distributed transactions ○ 2PC and compensation ● No external transaction coordinator required
  • 66. Local transactions ● Language construct for transactions transaction { } onretry { } committed { } aborted { }
  • 67. Distributed transactions ● New Ballerina microtransaction protocol ○ designed by Frank Leymann ● Goal is to make microservice transactions work smoothly ○ Initiator creates a coordinator ○ Participants have transaction infected to them transparently ○ Works OOTB for Ballerina distributed transactions and with sidecar for others ● Compensation ● WIP
  • 69. Part 9: Config & deployment
  • 70. Configuration ● Applications need to externalize configuration ● Two layers ○ config API ○ language support ● Language support for configuration ○ mark module level variables/attributes as configurable ○ externally refer to those and provide values ○ language startup system will read and population values before user code starts ○ (inspired by X Window System config model)
  • 71. Deployment ● Gone are the days of compiling and running programs ● Now ○ build ○ create Docker image ○ write YAML files ○ deploy ○ start ● Programmer is usually out of the loop on all of these ● Ballerina compiler supports extensibility for compilation process to include additional functions into compilation process
  • 74. Summary ● Ballerina is a programming language for network distributed applications ○ goal is to make writing such applications at least 3-5x faster, better, cheaper ● Brings fundamental concepts of networking, concurrency, data, security, deployment all together in an approach that offers both equivalent textual and graphical syntaxes ● Current implementation uses JVM but native compilation will come in 2020 ● Language still evolving but stable core ready to go ● Already used in production for commercial products ○ jBallerina 1.0 in July/August