A programming language and runtime
co-designed to be agile and integration simple.

Download >


The future apps we write increasingly depend upon programmable endpoints. The discipline of resilient communication between endpoints is integration. It is a domain of hard problems.

Ballerina is a simple programming language whose syntax and runtime address the hard problems of integration. As a Turing complete language, Ballerina enables agility with edit, build, and run cycles. Ballerina code is compiled into services that include transactions, embedded brokers and gateway runtimes.

Why did we build Ballerina?

Our team has worked on thousands of integration projects over two decades. We’ve seen and used almost every integration technique out there. They always end up on one side or the other of the integration gap.

Integration can either be done with integration products that simplify integration but are not agile, or with general purpose programming languages that are agile, but not integration simple.

Integration
Products

Integration products scale integration using configuration, not code. These products include ESBs, EAI, BPM, and DSLs. These approaches are integration simple, but not agile. They disrupt developer flow: the edit, build, run, test cycle.

Not Agile

The
Integration
Gap

General Purpose
Programming Languages

With languages like Java/Spring or JavaScript/Node, developers have flow, but take responsibility for solving the hard problems of integration. Developers write their own integration logic or use bolt-on frameworks. This approach is agile, but not integration simple.

Not Integration Simple

How Ballerina works

Ballerina's syntax, code, and compiler create runtime services and deployment artifacts that are cloud native ready for deployment within your IaaS, orchestrator, or service mesh of choice. The developer experience is designed to maintain flow, where the edit, build, debug cycle is rapid and integrated to your team's lifecycle toolchain.

RUNTIME ARCHITECTURE

BALLERINA API GATEWAY

Enforces performance and identity policies for running services. Configured and deployed through code annotations. Can run embedded in-line with a service, as a containered proxy managing multiple services, or with an API management solution like WSO2 API Manager.

BALLERINA SERVICE

Represent your API and execution logic. Services operate over different protocols and the internal code structure is compiled into API interfaces with support for OpenAPI and Swagger. Services communicate with endpoints, whether they are the calling client or other services.

BALLERINA BRIDGE

Enables legacy code and services to participate with Ballerina services in distributed transactions. The bridge wraps your existing service with a localhost proxy that enlists and brokers distributed transactions with invoking Ballerina services.

MESSAGE BROKER, TRANSACTION COORDINATOR, AND IDENTITY BROKER

Provide brokered infrastructure capabilities to Ballerina services participating in transactions, event-driven communications, or authentication flows. These components are embedded within services for single service deployments or can be separately deployed and scaled for managing multiple services.

DEPLOYMENT ARCHITECTURE

IAAS

Using code annotations and the build system, Ballerina services and other runtime components like the API gateway can be packaged for deployment into any cloud native environment. On IaaS environments, Ballerina services can run as a VM or a container, with images optionall pushed to a registry during build.

ORCHESTRATOR

Code annotations trigger compiler extensions that generate artifact packages of Ballerina components for different orchestrators such as Kubernetes or Cloud Foundry. Vendors or DevOps can add custom code annotations to generate environment-specific deployments, such as a custom blue-green deployment algorithm.

SERVICE MESH

Ballerina services can optionally delegate circuit breaking and transaction flow logic to a service mesh like Istio or Envoy if present. Ballerina services embed equivalent capabilities, if a service mesh is missing.

BALLERINA TOOLS

Get intellisense like autocomplete and debugging within VS Code and IntelliJ using our language server. Ballerina's keywords and syntax structure is designed to represent sequence diagrams. Visualize and edit Ballerina code with Ballerina Composer. Bonus - it also visualizes runtime dev traces.

LIFECYCLE ARCHITECTURE

BALLERINA TOOLS

Get intellisense like autocomplete and debugging within VS Code and IntelliJ using our language server. Ballerina's keywords and syntax structure is designed to represent sequence diagrams. Visualize and edit Ballerina code with Ballerina Composer. Bonus - it also visualizes runtime dev traces.

BALLERINA BUILD

Compiles services into optimized byte code for execution with a memory-tuned BVM. Project structure, dependency management, package management, and unit testing with Testerina are provided. Build locks make it easy to recreate services and deployments. Generate executables (.balx) or libraries (.balo).

CI/CD DEPLOYMENT

Deployment code annotations trigger build extensions that generate artifacts for continuous integration, continuous delivery, or orchestrator environments. Push build artifacts to your CI / CD system or skip it entirely.

REGISTRIES

Use or combine endpoint connectors, custom annotations and code functions as shareable packages. Push and pull versioned packages with Ballerina Central, a shared global repository.

Cloud Native Programming Language

Designed to be cloud-first, Ballerina has built-in support for modern web protocols and data formats, full power of a Turing-complete programming language, and native support for microservices architectures.

                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
                                    
                                
$ ballerina run hello.bal
ballerina: initiating service(s) in 'hello.bal'
ballerina: started HTTP/WS server connector 0.0.0.0:9090

$ curl -d "Ballerina" -X POST http://0.0.0.0:9090 Hello Ballerina!
$ ballerina run factors.bal
{"number":81,"factors":[{"factor":1},{"factor":81},{"factor":3},{"factor":27},{"factor":9},{"factor":9}]}
                                
$ ballerina build demo.bal
@docker                                  - complete 3/3
@kubernetes:Deployment                   - complete 1/1
@kubernetes:Service                      - complete 1/1

Run following command to deploy kubernetes artifacts: kubectl apply -f /Users/user/proj/kubernetes/
$ kubectl apply -f /Users/user/proj/kubernetes/ deployment "ballerina-demo" created service "ballerina-demo" created
$ kubectl get pods NAME READY STATUS RESTARTS AGE ballerina-demo-74b6fb687c-mbrq2 1/1 Running 0 10s
$ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ballerina-demo NodePort 10.98.238.0 9090:31977/TCP 24s kubernetes ClusterIP 10.96.0.1 443/TCP 2d
$ curl -X POST http://localhost:31977/demo Hello World!

                                

                                

                            

Ballerina makes it easy to build APIs, provide and consume HTTP, WebSocket, gRPC, Protobuf, and other services. This example demonstrates a simple REST API built with Ballerina.

Ballerina’s built-in support for HTTP includes session-handling, Swagger generation, chunking, CORS, redirects, failover, load-balancing, circuit breaker pattern, return code, data format enforcement, error handling, and much more.

Note how the "match" command in the code is used to handle a union-type return: if the return value is a string - normal processing happens. If our service did not get the string it expected - we use error-handling logic instead.

Ballerina is a full, Turing-complete programming language. It has all the capabilities and powers of a modern programming language.

This code sample (generating a random integer, finding its factors, and outputting those as JSON) demonstrates the use of math library, functions, standard types, arrays, flow controls such as the while loop and the if statement.

Note that json is a first-class data type just like int.

This example is using a main function. Ballerina applications typically use those for regular console apps. Microservices that expose some functionality as APIs typically do not have main, and have services instead.

Ballerina makes it easy to call functions and remote services asynchronously, wait for results when needed, check status and cancel asynchronous execution, fork and join threads, and pass data between threads.

Asynchronous calls to functions and endpoints create a future variable that can then be passed further to other calls is needed. Once the actual value is needed, the wait operator can be used to wait for the actual return.

Functions can split their execution into multiple worker threads. Threads execute asynchronously but can exchange data and wait for data from other threads. Threads can join using different conditions (all end, some end).

JSON and XML are first class citizens in Ballerina.

You can easily construct them, manipulate their elements, enforce their schema, get and return them from services, transform one into the other.

Ballerina applications can have docker and Kubernetes annotations added to their services and endpoints.

Compiler reads these annotations and uses them to identify which endpoints need to be exposed and how, and which services need to become what kind of containers.

Ballerina compiler is extensible with packages. This particular example is using the Kubernetes package to generate Kubernetes artifacts and docker image. Other platforms such as Cloud Foundry, Mesos, and so on can have their own packages, annotations, and artifact generation.

Ballerina is a compiled language with both compile-time and run-time type safety enforcement.

All variables as well as function parameters and returns need to be typed. This provides for much better developer experience in all major IDEs (with tab completion, tooltips, and code snippets), and makes sure that most issues get caught by Ballerina parser and compiler.

JSON and XML schemas can be enforced to ensure that your code gets the data that it needs.

Functions can return union types that can be the actual data, error or null. Your code can then use match to resolve what got returned and handle properly.

Integration Framework

Ballerina is a language designed to be integration simple. Based around the interactions of sequence diagrams, Ballerina has built-in support for common integration patterns and connectors, including distributed transactions, compensation and circuit breakers. With first-class support for JSON and XML, Ballerina makes it simple and effective to build robust integration across network endpoints.

                            
                        
                            
                        
                            
                        
ballerina run test.balx
ballerina: initiating service(s) in 'test.balx'
ballerina: started HTTP/WS server connector 0.0.0.0:9090

curl -X POST -d '{"year":2019}' http://localhost:9090/payment {"name":"","cardnumber":"","month":0,"year":2019,"cvc":0}

curl -X POST -d '{"year":"twenty-ten"}' http://localhost:9090/payment cannot convert 'json' to type 'Payment': error while mapping 'year': incompatible types: expected 'int', found 'string' in json

                            
                            

Ballerina objects can be simple structures or more complex objects with public and private fields.

Integration often has to deal with complex distributed errors. Ballerina has powerful error handling capabilities based around union types. The /check/ operator makes it easy to pass the error back to the caller.

Converting a JSON into an object simply involves casting it as that object. An error is returned if the JSON has the wrong schema.

This is a valid JSON, and the empty fields are assumed

This JSON does not match the required schema and will return an error

The Twitter connector is just one example of many. It will be pulled from the Ballerina Central Repository as needed.

Ballerina has a lightweight microservice message broker that provides support for the AMQP protocol and offers asynchronous reliable messaging using queues and topics. Integrating Ballerina services with AMQP is simple.

Support for the Ballerina Message Broker is provided by the built-in “ballerina/mb” package

Messaging endpoints can listen or publish to queues or topics. This listener endpoint will create an event for every incoming message

A message-driven service is invoked every time a message is received on a queue or topic.

Try the language with
Ballerina by Example

Ballerina by Example teaches you the language incrementally with commented examples that cover every nuance of our syntax.

Learn integration with
Ballerina by Guide

Ballerina by Guide are long form examples that showcase how to build different types of integrations using a complete development lifecycle including IDE configuration, packages, dependencies, coding, unit testing, deployment and observability.

Open Source

Apache-licensed software and community-driven projects.

Ballerina A programming language and service runtime for orchestration and composition of endpoints
Ballerina.io The home of the Ballerina Platform
Ballerina Bridge A container that attaches transactions and resilience to running services
Ballerina API Gateway enforce security and runtime policies
Ballerina Message Broker Scalable broker for persistent and asynchronous messaging