SlideShare a Scribd company logo
Better java for Java microservice developers
Sanjiva Weerawarana, Ph.D.
Ballerina Product Manager
Founder & Consultant, WSO2
Founder, Chairman & Chief Architect, Lanka Software Foundation
sanjiva@weerawarana.org
Java Colombo Meetup; November 05, 2019; Colombo
Agenda
• Motivation
• How is Ballerina different?
• What are some good entry use cases?
• Status & future work
11/5/19 2
Why do we need yet another language?
• Digital businesses are all about the network
– Disaggregation is the norm
– Applications compose functionality, often 3rd party SaaS
• Minimalization of computing
– Deployment: Hardware 🡪 VMs 🡪 Containers 🡪 Serverless
– Architecture: SOA 🡪 Microservices 🡪 Functions
• Technology for integrating smaller pieces is fundamental
– Servers 🡪 sidecars 🡪 code
– Middleware is dead; middleware is everywhere
11/5/19 3
Spectrum of languages from systems to glue languages
• Assembly
• Rust, C
• C++
• Go, Java, C#
• Ballerina
• TypeScript
• Python, JavaScript
• PowerShell, Bourne shell, TCL, AWK
11/5/19 4
Design goals for Ballerina
• Provide abstractions for networking
• Use sequence diagrams as the visual model
• Minimize cognitive load
• Leverage familiarity
• Enable a semantically-rich static program model
• Provide a complete platform, not just a language
• Allow multiple implementations, based on different runtime environments
11/5/19 5
https://blog.jclark.com/2019/09/ballerina-programming-language-part-1.html
Language basics: Hello world
import ballerina/io;
public function main (string name) {
worker w1 {
io:println ("Hello ", name, " from worker w1");
}
worker w2 {
io:println ("Hello ", name, " from worker w2");
}
io:println ("Hello ", name, " from default worker");
}
11/5/19 6
Language basics: Listeners & Services
import ballerina/http;
public listener http:Listener staffServer = new (9090);
@http:ServiceConfig {
basePath: "/institutions"
}
service InstitutionsService on staffServer {
@http:ResourceConfig {
methods: ["GET"],
path: "/"
}
resource function listAll (http:Caller caller, http:Request req)
returns error? {
json[] list = getInstitutions();
check caller->ok(<json>list);
}
}
11/5/19 7
Language basics: Client Objects
import ballerina/io;
import ballerina/http;
http:Client hc = new ("http://localhost:9090");
public function main() returns error? {
http:Response hr;
hr = check hc->post (“/hello”, data);
json jr = <@untainted> check hr.getJsonPayload();
return jr.uuid.toString();
}
11/5/19 8
Ballerina by Example
11/5/19 9
How is Ballerina different?
• Network in the language
• Sequence diagrams for programming
• Structural, open by default typing
• From code to cloud
• Batteries included
• Developer first
11/5/19 10
Programming the network
• BSD sockets
– Network connections are just byte streams
• Stubs & skeletons
– Offers RPC experience that hides network details
• Network realities
– Unreliable, latent, event driven, concurrent, unsafe, data not objects
• Most languages do not address networking aspects
– Left to libraries and now to sidecars
– That means no static verification possible
11/5/19 11
Ballerina network abstractions
11/5/19 12
Service
Service
Service
Dispatche
r
Listener Client
Service
(Caller)
Client Object
(Callback)
Serviceresource
method
Service
remote
method
Client Object
Service & client typing
• Network interactions are governed by
– Application protocol
– Data types
– Message sequencing
• Type system captures these to make this explicit to the programmer
– Goal is to make network interactions be type checked like local function calls are
– For services, currently done thru annotations
– Planning to use session types for message sequencing
11/5/19 13
Outbound resiliency
• Network interactions
– Can fail intermittently
– May require alternate paths
– May require controlled failure management
• Programmers need to use techniques like
– Load balancing, failover, bulkheading
• Ballerina platform components build these in
– Automatic retry
– Failover
– Load balancing
11/5/19 14
Non-blocking & asynchronous
• All I/O in Ballerina is non-blocking at execution thread level
– No need for callbacks – programmed synchronously as if blocking
• Asynchronous calls received via services
– Services act as event handlers
– E.g. Websocket client registers a service to receive async messages received from other end
11/5/19 15
Service concurrency
• Resource methods are concurrently invoked for each incoming message
• Services are stateless
– Session state is possible
• Dispatchers are responsible for invoking resources on its own strand
11/5/19 16
Network safety & security
• Data coming over the network is by default considered tainted
– Must be cleaned before given to a taint-sensitive user, or taintedness propagates
• Detected and flagged at compile-time
• @tainted and @untainted annotations
– E.g. cannot inadvertently insert tainted data to a database
• Safety: Authentication and authorization are part of all listeners and clients
• Planning to build in letsencrypt.org to HTTP services
11/5/19 17
Error handling
• Errors are first class values in Ballerina
– Not part of any other value
• Function returns union with error type to indicate errors
– function post (json data) returns string|error
• Errors must be handled
• Errors that are “unhandleable” are panics
11/5/19 18
Sequence diagrams
• Often used to explain behavior of concurrent scenarios
• Ballerina uses sequence diagrams for network interactions and concurrency
• Debugging with the diagram in VSCode will be released soon
11/5/19 19
Concurrency
• Workers
– Workers are concurrent bits of code
– Workers can communicate with each other via message passing
– Statically type checked for deadlock-free execution
• Currently limited, future more flexible with session types
– Parallel actors in sequence diagram
• Strands
– Logical threads of execution that runs a strand of workers - a call stack
– Created by a named worker
– Run independently until blocked due to worker to worker interaction
– Represented by futures
11/5/19 20
Futures
• Futures represent strands
• Type is the return type of the worker running in the strand, including any errors
• A named worker defines a variable of type future<T> where T is the return type of
the worker.
• Futures are first-class - so can be passed as parameters etc.
11/5/19 21
Concurrency
11/5/19 22
function foo () {
worker GetScores {
io:print("Got scores");
}
worker GetStats {
io:print("Got stats");
}
io:print("Other work");
}
Ballerina type system
• Not object oriented: OO is wrong model or network distributed applications
– Network transparency doesn’t work
– Can’t send code over the network
– Object serialization/deser causes tight coupling
• Type system works as a schema too
– 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
11/5/19 23
Ballerina type system
11/5/19 24
Just two data structures
• Ballerina has two fundamental data structures
– lists: ordered list
– mappings: mappings from strings to values
• Two ways to type mappings
– records (both open and closed)
– maps
• Two ways to type lists
– tuples
– arrays
• Exact match for JSON
11/5/19 25
“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
Code to cloud
• In the old days ..
– Write code, compile and run it on a server (hardware)
• Now ..
– Write code, build, create Docker image, put into K8s deployment, run, observe
• Yet ..
– Today’s process is fractured and caught up lots of YAML
11/5/19 26
Build service to Docker image
11/5/19 27
import ballerina/http;
import ballerina/log;
import ballerinax/docker;
@docker:Expose {}
listener http:Listener helloWorldEP = new(9090);
@docker:Config {
name: "helloworld",
tag: "v1.0"
}
@http:ServiceConfig {
basePath: "/helloWorld"
}
service helloWorld on helloWorldEP {
resource function sayHello(http:Caller outboundEP,
http:Request request) returns error? {
http:Response response = new;
response.setTextPayload("Hello World from Docker ! n");
check outboundEP->respond(response);
}
}
% ballerina build docker.bal
Ballerina service to K8s deployment
11/5/19 28
import ballerina/config;
import ballerina/http;
import ballerinax/kubernetes;
@kubernetes:Service {
serviceType: "NodePort"
}
@kubernetes:Ingress {
hostname: "abc.com"
}
listener http:Listener helloWorldEP = new(9090);
@kubernetes:Deployment {
livenessProbe: true,
image: "kubernetes:v.1.0"
}
@http:ServiceConfig {
basePath: "/helloWorld"
}
service helloWorld on helloWorldEP {
@http:ResourceConfig {
methods: ["GET"],
path: "/config/{user}"
}
resource function getConfig(http:Caller outboundEP, http:Request request, string user) returns erro
Pluggable to any deployment environment
• Annotations are processed by compiler extensions
• Extensions can take control of codegen process and generate whatever it wants
• Goal is to allow these extensions to come from Ballerina Central
11/5/19 29
“Batteries included” standard library
• HTTP
• HTTP/2
• WebSockets
• WebSub
• AMQP
• MQTT
• (S)FTP(S)
• NATS
• Kafka
• gRPC
• XML
• JSON
• OpenAPI
• Sockets
• JWT
• OAuth2
• OpenTracing
• …
11/5/19 30
Developer first
• Structured documentation using Ballerina flavored markdown
– Code is read far more than its written
• Testing framework
• Module management, sharing, publishing, pulling via Ballerina Central
• IDE plugins for VSCode and IntelliJ IDEA
– Using Language Server Protocol
• Observability (metrics, tracing, logging) with Open Tracing
11/5/19 31
What are some good entry use cases?
• BFF services
• Data services
• (with the Java impl) Java microservices
• Easiest to write K8s services
• Integration developers
• CLIs that incorporate network services
• Infra as code (ala Pulumi)
• Microgateways
• Language to learn to code in
11/5/19 32
Interoperating with Java
11/5/19 33
import ballerinax/java;
import ballerina/io;
public function main() {
handle jRuntime = getRuntime();
int availableProcessors = getAvailableProcessors(jRuntime);
io:println(availableProcessors);
}
function getRuntime() returns handle = @java:Method {
// If the Ballerina function name is same as the Java method name, the following attribute is not needed
name: "getRuntime",
class: "java.lang.Runtime"
} external;
function getAvailableProcessors(handle jRuntime) returns int = @java:Method {
name: "availableProcessors",
class: "java.lang.Runtime"
} external;
Status
• 1.0 released
– Based on 2019R3 language spec
– jBallerina compiles to Java bytecodes
– VSCode & Idea plugins based on language server
– Ballerina central
– Tools for testing, documentation, OpenAPI, gRPC
• 100% open source
– https://github.com/ballerina-platform
– Spec under CC
• https://ballerina.io/
11/5/19 34
Future work
• Parametric typing
• Service typing
• Transactions, both local and distributed
• Improved concurrency safety
• Language integrated query
• Streaming data and streaming query
• Declarative data transformation
• Improved configurability
• Long running execution
• …
• Implementation: nballerina with LLVM
11/5/19 35
Summary
• Ballerina is an attempt to build a modern industrial grade programming language
for the future with lots of network endpoints
• Type system is designed to make network data processing easier
• First class network services along with functions/objects
• Framework to encourage more secure code
• Fully open source and developed openly
11/5/19 36

More Related Content

PPTX
A CMD Core Model for CLARIN Web Services
PPTX
Where the &amp;$%! did this come from e resources in alma%2-f_primo a teachi...
PPTX
Your API is Bad and You Should Feel Bad
PPTX
2014 01-21-mpi-community-feedback
PPTX
Multi-Lingual Accumulo Communications
PDF
Introduction to OFI
PPTX
An introduction . Programmatic access to interaction resources
PPT
Best DotNet Training in Delhi
A CMD Core Model for CLARIN Web Services
Where the &amp;$%! did this come from e resources in alma%2-f_primo a teachi...
Your API is Bad and You Should Feel Bad
2014 01-21-mpi-community-feedback
Multi-Lingual Accumulo Communications
Introduction to OFI
An introduction . Programmatic access to interaction resources
Best DotNet Training in Delhi

What's hot (13)

PDF
From silex to symfony and viceversa
PDF
Alfresco Day Milano 2016 - Demo Data
PDF
Ekon20 mORMot SOA Delphi Conference
PPT
PPT
PDF
The Virtual Repository
PPT
Net framework
PDF
Ballerina- A programming language for the networked world
PPTX
Datasnap
PDF
BPM-4 Migration from jBPM to Activiti
PDF
On being RESTful
PDF
Merging two big Symfony based applications - SymfonyCon 2017
PPTX
Advanced java course
From silex to symfony and viceversa
Alfresco Day Milano 2016 - Demo Data
Ekon20 mORMot SOA Delphi Conference
The Virtual Repository
Net framework
Ballerina- A programming language for the networked world
Datasnap
BPM-4 Migration from jBPM to Activiti
On being RESTful
Merging two big Symfony based applications - SymfonyCon 2017
Advanced java course
Ad

Similar to [Java Colombo Meetup] The better java for Java microservices developers (20)

PPTX
APIs, STOP Polling, lets go Streaming
PDF
Going FaaSter, Functions as a Service at Netflix
PDF
Three years of OFELIA - taking stock
ZIP
How we use Twisted in Launchpad
PPTX
Lecture 3 computer communications and networks
PDF
Application Layer Application Layer Application Layer
PPT
Design an Implementation of A Messaging and Resource Sharing Software
PPTX
Envoy @ Lyft: developer productivity (kubecon 2.0)
PPTX
5_6278455688045789623.pptx
PDF
Chapter 3 - Computer Networking a top-down Approach 7th
PDF
Ballerina Serverless with Kubeless
PDF
Ballerina Serverless with Kubeless
PPTX
SESSION8_AWS how to deploy the resources and services
PDF
Polyakov how i will break your enterprise. esb security and more
PDF
Web Architecture and Technologies
PPTX
signalr
PDF
Hands on with CoAP and Californium
PPTX
#3 calicut meetup - understanding slb, dlb and web sockets
PPTX
Iso osi layers reference model of internet .pptx
PDF
Unit 6 - Netwohhhhhddddrking in Java.pdf
APIs, STOP Polling, lets go Streaming
Going FaaSter, Functions as a Service at Netflix
Three years of OFELIA - taking stock
How we use Twisted in Launchpad
Lecture 3 computer communications and networks
Application Layer Application Layer Application Layer
Design an Implementation of A Messaging and Resource Sharing Software
Envoy @ Lyft: developer productivity (kubecon 2.0)
5_6278455688045789623.pptx
Chapter 3 - Computer Networking a top-down Approach 7th
Ballerina Serverless with Kubeless
Ballerina Serverless with Kubeless
SESSION8_AWS how to deploy the resources and services
Polyakov how i will break your enterprise. esb security and more
Web Architecture and Technologies
signalr
Hands on with CoAP and Californium
#3 calicut meetup - understanding slb, dlb and web sockets
Iso osi layers reference model of internet .pptx
Unit 6 - Netwohhhhhddddrking in Java.pdf
Ad

More from Ballerinalang (20)

PDF
Building Real-time Systems with WebSub - Ballerina Community Call - 11/30/2021
PDF
Managing dependencies in ballerina
PDF
[Ballerina Community Call] Language Integrated Queries
PDF
[Community Call] Ballerina Swan Lake HTTP Module Changes
PDF
Ballerina Community Call 8: Highlights of Ballerina Swan Lake and Introducing...
PDF
[GID Live] Automatic Microservices Observability with Ballerina
PDF
[GID Live] Open-Source Cloud-Native Programming Language
PDF
[Ballerina Community Call] Services and Network Communication Updates in Swan...
PDF
[Ballerina Community Call] Java Interoperability
PDF
[Ballerina Community Call] Data Access in Ballerina
PDF
Code to Kubernetes: Languages of Infrastructure
PDF
[Cloud DC Meetup] Cloud Native Development with Ballerina
PDF
[DevOps Pro Europe 2020] The Cloud-Native and DevOps Friendly Programming Lan...
PDF
[DevOps Pro Europe 2020] From Code to Cloud
PDF
[DeveloperWeek 2020] Conquering Network Distributed Applications Using Ballerina
PDF
[Cloud-Native and Kubernetes Meetup in Silicon Valley] Ballerina - Cloud Nati...
PDF
[Downtown San Jose DevOps Meetup] Ballerina - A Programming Language for Clou...
PDF
[DeveloperWeek Austin 2019] Microservices in Practice with Ballerina, Kuberne...
PDF
[ApacheCon NA 2019] Re-inventing Middleware in a Programming Language
PDF
[ApacheCon NA 2019] Conquering Network Distributed Applications Using the Bal...
Building Real-time Systems with WebSub - Ballerina Community Call - 11/30/2021
Managing dependencies in ballerina
[Ballerina Community Call] Language Integrated Queries
[Community Call] Ballerina Swan Lake HTTP Module Changes
Ballerina Community Call 8: Highlights of Ballerina Swan Lake and Introducing...
[GID Live] Automatic Microservices Observability with Ballerina
[GID Live] Open-Source Cloud-Native Programming Language
[Ballerina Community Call] Services and Network Communication Updates in Swan...
[Ballerina Community Call] Java Interoperability
[Ballerina Community Call] Data Access in Ballerina
Code to Kubernetes: Languages of Infrastructure
[Cloud DC Meetup] Cloud Native Development with Ballerina
[DevOps Pro Europe 2020] The Cloud-Native and DevOps Friendly Programming Lan...
[DevOps Pro Europe 2020] From Code to Cloud
[DeveloperWeek 2020] Conquering Network Distributed Applications Using Ballerina
[Cloud-Native and Kubernetes Meetup in Silicon Valley] Ballerina - Cloud Nati...
[Downtown San Jose DevOps Meetup] Ballerina - A Programming Language for Clou...
[DeveloperWeek Austin 2019] Microservices in Practice with Ballerina, Kuberne...
[ApacheCon NA 2019] Re-inventing Middleware in a Programming Language
[ApacheCon NA 2019] Conquering Network Distributed Applications Using the Bal...

Recently uploaded (20)

PDF
Hybrid model detection and classification of lung cancer
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
August Patch Tuesday
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Getting Started with Data Integration: FME Form 101
PPTX
1. Introduction to Computer Programming.pptx
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Modernising the Digital Integration Hub
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
STKI Israel Market Study 2025 version august
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hybrid model detection and classification of lung cancer
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
August Patch Tuesday
NewMind AI Weekly Chronicles - August'25-Week II
A contest of sentiment analysis: k-nearest neighbor versus neural network
Final SEM Unit 1 for mit wpu at pune .pptx
observCloud-Native Containerability and monitoring.pptx
Getting Started with Data Integration: FME Form 101
1. Introduction to Computer Programming.pptx
TLE Review Electricity (Electricity).pptx
Modernising the Digital Integration Hub
DP Operators-handbook-extract for the Mautical Institute
Web App vs Mobile App What Should You Build First.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
cloud_computing_Infrastucture_as_cloud_p
gpt5_lecture_notes_comprehensive_20250812015547.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
STKI Israel Market Study 2025 version august
Developing a website for English-speaking practice to English as a foreign la...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf

[Java Colombo Meetup] The better java for Java microservices developers

  • 1. Better java for Java microservice developers Sanjiva Weerawarana, Ph.D. Ballerina Product Manager Founder & Consultant, WSO2 Founder, Chairman & Chief Architect, Lanka Software Foundation sanjiva@weerawarana.org Java Colombo Meetup; November 05, 2019; Colombo
  • 2. Agenda • Motivation • How is Ballerina different? • What are some good entry use cases? • Status & future work 11/5/19 2
  • 3. Why do we need yet another language? • Digital businesses are all about the network – Disaggregation is the norm – Applications compose functionality, often 3rd party SaaS • Minimalization of computing – Deployment: Hardware 🡪 VMs 🡪 Containers 🡪 Serverless – Architecture: SOA 🡪 Microservices 🡪 Functions • Technology for integrating smaller pieces is fundamental – Servers 🡪 sidecars 🡪 code – Middleware is dead; middleware is everywhere 11/5/19 3
  • 4. Spectrum of languages from systems to glue languages • Assembly • Rust, C • C++ • Go, Java, C# • Ballerina • TypeScript • Python, JavaScript • PowerShell, Bourne shell, TCL, AWK 11/5/19 4
  • 5. Design goals for Ballerina • Provide abstractions for networking • Use sequence diagrams as the visual model • Minimize cognitive load • Leverage familiarity • Enable a semantically-rich static program model • Provide a complete platform, not just a language • Allow multiple implementations, based on different runtime environments 11/5/19 5 https://blog.jclark.com/2019/09/ballerina-programming-language-part-1.html
  • 6. Language basics: Hello world import ballerina/io; public function main (string name) { worker w1 { io:println ("Hello ", name, " from worker w1"); } worker w2 { io:println ("Hello ", name, " from worker w2"); } io:println ("Hello ", name, " from default worker"); } 11/5/19 6
  • 7. Language basics: Listeners & Services import ballerina/http; public listener http:Listener staffServer = new (9090); @http:ServiceConfig { basePath: "/institutions" } service InstitutionsService on staffServer { @http:ResourceConfig { methods: ["GET"], path: "/" } resource function listAll (http:Caller caller, http:Request req) returns error? { json[] list = getInstitutions(); check caller->ok(<json>list); } } 11/5/19 7
  • 8. Language basics: Client Objects import ballerina/io; import ballerina/http; http:Client hc = new ("http://localhost:9090"); public function main() returns error? { http:Response hr; hr = check hc->post (“/hello”, data); json jr = <@untainted> check hr.getJsonPayload(); return jr.uuid.toString(); } 11/5/19 8
  • 10. How is Ballerina different? • Network in the language • Sequence diagrams for programming • Structural, open by default typing • From code to cloud • Batteries included • Developer first 11/5/19 10
  • 11. Programming the network • BSD sockets – Network connections are just byte streams • Stubs & skeletons – Offers RPC experience that hides network details • Network realities – Unreliable, latent, event driven, concurrent, unsafe, data not objects • Most languages do not address networking aspects – Left to libraries and now to sidecars – That means no static verification possible 11/5/19 11
  • 12. Ballerina network abstractions 11/5/19 12 Service Service Service Dispatche r Listener Client Service (Caller) Client Object (Callback) Serviceresource method Service remote method Client Object
  • 13. Service & client typing • Network interactions are governed by – Application protocol – Data types – Message sequencing • Type system captures these to make this explicit to the programmer – Goal is to make network interactions be type checked like local function calls are – For services, currently done thru annotations – Planning to use session types for message sequencing 11/5/19 13
  • 14. Outbound resiliency • Network interactions – Can fail intermittently – May require alternate paths – May require controlled failure management • Programmers need to use techniques like – Load balancing, failover, bulkheading • Ballerina platform components build these in – Automatic retry – Failover – Load balancing 11/5/19 14
  • 15. Non-blocking & asynchronous • All I/O in Ballerina is non-blocking at execution thread level – No need for callbacks – programmed synchronously as if blocking • Asynchronous calls received via services – Services act as event handlers – E.g. Websocket client registers a service to receive async messages received from other end 11/5/19 15
  • 16. Service concurrency • Resource methods are concurrently invoked for each incoming message • Services are stateless – Session state is possible • Dispatchers are responsible for invoking resources on its own strand 11/5/19 16
  • 17. Network safety & security • Data coming over the network is by default considered tainted – Must be cleaned before given to a taint-sensitive user, or taintedness propagates • Detected and flagged at compile-time • @tainted and @untainted annotations – E.g. cannot inadvertently insert tainted data to a database • Safety: Authentication and authorization are part of all listeners and clients • Planning to build in letsencrypt.org to HTTP services 11/5/19 17
  • 18. Error handling • Errors are first class values in Ballerina – Not part of any other value • Function returns union with error type to indicate errors – function post (json data) returns string|error • Errors must be handled • Errors that are “unhandleable” are panics 11/5/19 18
  • 19. Sequence diagrams • Often used to explain behavior of concurrent scenarios • Ballerina uses sequence diagrams for network interactions and concurrency • Debugging with the diagram in VSCode will be released soon 11/5/19 19
  • 20. Concurrency • Workers – Workers are concurrent bits of code – Workers can communicate with each other via message passing – Statically type checked for deadlock-free execution • Currently limited, future more flexible with session types – Parallel actors in sequence diagram • Strands – Logical threads of execution that runs a strand of workers - a call stack – Created by a named worker – Run independently until blocked due to worker to worker interaction – Represented by futures 11/5/19 20
  • 21. Futures • Futures represent strands • Type is the return type of the worker running in the strand, including any errors • A named worker defines a variable of type future<T> where T is the return type of the worker. • Futures are first-class - so can be passed as parameters etc. 11/5/19 21
  • 22. Concurrency 11/5/19 22 function foo () { worker GetScores { io:print("Got scores"); } worker GetStats { io:print("Got stats"); } io:print("Other work"); }
  • 23. Ballerina type system • Not object oriented: OO is wrong model or network distributed applications – Network transparency doesn’t work – Can’t send code over the network – Object serialization/deser causes tight coupling • Type system works as a schema too – 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 11/5/19 23
  • 25. Just two data structures • Ballerina has two fundamental data structures – lists: ordered list – mappings: mappings from strings to values • Two ways to type mappings – records (both open and closed) – maps • Two ways to type lists – tuples – arrays • Exact match for JSON 11/5/19 25 “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
  • 26. Code to cloud • In the old days .. – Write code, compile and run it on a server (hardware) • Now .. – Write code, build, create Docker image, put into K8s deployment, run, observe • Yet .. – Today’s process is fractured and caught up lots of YAML 11/5/19 26
  • 27. Build service to Docker image 11/5/19 27 import ballerina/http; import ballerina/log; import ballerinax/docker; @docker:Expose {} listener http:Listener helloWorldEP = new(9090); @docker:Config { name: "helloworld", tag: "v1.0" } @http:ServiceConfig { basePath: "/helloWorld" } service helloWorld on helloWorldEP { resource function sayHello(http:Caller outboundEP, http:Request request) returns error? { http:Response response = new; response.setTextPayload("Hello World from Docker ! n"); check outboundEP->respond(response); } } % ballerina build docker.bal
  • 28. Ballerina service to K8s deployment 11/5/19 28 import ballerina/config; import ballerina/http; import ballerinax/kubernetes; @kubernetes:Service { serviceType: "NodePort" } @kubernetes:Ingress { hostname: "abc.com" } listener http:Listener helloWorldEP = new(9090); @kubernetes:Deployment { livenessProbe: true, image: "kubernetes:v.1.0" } @http:ServiceConfig { basePath: "/helloWorld" } service helloWorld on helloWorldEP { @http:ResourceConfig { methods: ["GET"], path: "/config/{user}" } resource function getConfig(http:Caller outboundEP, http:Request request, string user) returns erro
  • 29. Pluggable to any deployment environment • Annotations are processed by compiler extensions • Extensions can take control of codegen process and generate whatever it wants • Goal is to allow these extensions to come from Ballerina Central 11/5/19 29
  • 30. “Batteries included” standard library • HTTP • HTTP/2 • WebSockets • WebSub • AMQP • MQTT • (S)FTP(S) • NATS • Kafka • gRPC • XML • JSON • OpenAPI • Sockets • JWT • OAuth2 • OpenTracing • … 11/5/19 30
  • 31. Developer first • Structured documentation using Ballerina flavored markdown – Code is read far more than its written • Testing framework • Module management, sharing, publishing, pulling via Ballerina Central • IDE plugins for VSCode and IntelliJ IDEA – Using Language Server Protocol • Observability (metrics, tracing, logging) with Open Tracing 11/5/19 31
  • 32. What are some good entry use cases? • BFF services • Data services • (with the Java impl) Java microservices • Easiest to write K8s services • Integration developers • CLIs that incorporate network services • Infra as code (ala Pulumi) • Microgateways • Language to learn to code in 11/5/19 32
  • 33. Interoperating with Java 11/5/19 33 import ballerinax/java; import ballerina/io; public function main() { handle jRuntime = getRuntime(); int availableProcessors = getAvailableProcessors(jRuntime); io:println(availableProcessors); } function getRuntime() returns handle = @java:Method { // If the Ballerina function name is same as the Java method name, the following attribute is not needed name: "getRuntime", class: "java.lang.Runtime" } external; function getAvailableProcessors(handle jRuntime) returns int = @java:Method { name: "availableProcessors", class: "java.lang.Runtime" } external;
  • 34. Status • 1.0 released – Based on 2019R3 language spec – jBallerina compiles to Java bytecodes – VSCode & Idea plugins based on language server – Ballerina central – Tools for testing, documentation, OpenAPI, gRPC • 100% open source – https://github.com/ballerina-platform – Spec under CC • https://ballerina.io/ 11/5/19 34
  • 35. Future work • Parametric typing • Service typing • Transactions, both local and distributed • Improved concurrency safety • Language integrated query • Streaming data and streaming query • Declarative data transformation • Improved configurability • Long running execution • … • Implementation: nballerina with LLVM 11/5/19 35
  • 36. Summary • Ballerina is an attempt to build a modern industrial grade programming language for the future with lots of network endpoints • Type system is designed to make network data processing easier • First class network services along with functions/objects • Framework to encourage more secure code • Fully open source and developed openly 11/5/19 36