Ballerina language is an open-source, cloud-native programming language designed to ease the burden of integration development associated with enterprise applications. Ballerina simplifies how a program talks over the network, usually to an application program interface (API). It attempts to create an integrated system by bringing together the essential concepts, ideas and tools of a distributed system integration and offering a type safe, concurrent environment in order to support APIs. Type safe is code that can only access the memory locations it is programmed to access.Content Continues Below
Ballerina is a general purpose, strongly typed programming language with both textual and graphical syntaxes. Ballerina is an attempt to resolve the gap between integration products and general purpose programming languages.
According to Tyler Jewell, CEO of WSO2, more than 50% of the time and cost for digital transformation and API projects within enterprises is integration. The Ballerina language was built to make it easier to integrate disparate services, systems and data, so that developers can spend more time focusing on delivering features and functionality.
Many of the programming languages and integration products that developers use today embed programming logic within YAML, XML or other configuration-based files. In cloud or container environments, external APIs are required that handle the different languages to connect programs. Developers must write drivers or plugins and wrestle with detailed programming constructs to make them work.
Ballerina empowers developers to write code to integrate items rather than use complex configuration-based integration schemes. Ballerina’s underlying value type system makes JSON and XML tables, records, maps and errors primitives, eliminating the need for libraries to work with these fundamental data structures. As a result, developers can do a lot of data structure manipulation using simple constructs within the source code.
Ballerina is designed with an architecture based on modules that are easily shared. It is intended to be a traditional declarative language, similar to the C programming language or Java. It is not designed to be a domain specific language (DSL) that is used only for integration tasks. The type safe, concurrent environment offered by Ballerina allows the implementation of microservices with dispersed transactions, dependable messaging, workflow and stream processing. In addition, it is a programming language designed for cloud computing.
The language is designed around the following core design principles:
- Sequence diagram - In a sequence diagram, interactions between different actors are represented graphically, much the same way developers document interconnected systems. Ballerina’s syntax is structured to let any tool or system derive a sequence diagram. Every Ballerina program, including synchronous and asynchronous calls, can be displayed as a sequence diagram of its flow with endpoints.
- Observability - The language supports microservice based metrics, tracing and logging without adding an extra library. The binary produced by Ballerina automatically generates the data. In order to obtain these observability features, users simply configure the end-clients to analyze and display the data.
- Concurrency workers - The Ballerina language’s execution model is composed of lightweight parallel execution units, known as workers. Workers operate with a full non-blocking policy in which no function lacks an executing thread. This creates sequence concurrency and workers become independent concurrent actors that do not share state but can interact using messages.
- Network aware - Ballerina has a structural type system with primitive, object, union and tuple Network systems return messages with different payload types and errors. Ballerina’s type system embraces this variability with an approach based on union types. This type safe model incorporates type inference for assignment to provide numerous compiled time integrity checks for network-bound payloads.
- Environment aware - Ballerina language and its components are made to be used in distributed, event-driven architectures (EDA). As a result, every service written within Ballerina occupies an environment that could include other services, legacy services, databases, cloud orchestrators, API gateways, identity gateways, service meshes and message brokers. Ballerina’s language and annotation extensions treat these components as syntactical objects and relationships as decorated annotations.
- DevOps ready - Ballerina includes various subsystems—such as unit test framework, build system, dependency management and versioning—that are necessary for DevOps, as part of its core distribution.
- Security - Security is included in Ballerina with a group of checks performed in the integrated development environment (IDE) with a security-aware compiler. The compiler performs a static analysis and checks the code for flaws and vulnerabilities. Ballerina also includes runtime analysis and every function possesses security annotations. The @sensitive annotation can signal the program to only accept trusted data, preventing the risk of SQL injection and other threats. The @tainted annotation can be used to highlight any computation that is considered suspicious.
- Built-in container support - The built-in container support allows code to be annotated so that the compiler instantly creates a Dockerfile and pairs it with an image that can then be run as a container. A library is also offered for the Kubernetes engine.
In addition, Ballerina can run with or without a service mesh. Since it is written as an integration language, Ballerina can perform duties similar to a service mesh, providing observability, multi-protocol support and service discovery. However, the language also works well with an external service mesh, such as Istio.
Ballerina is also capable of working with streaming data by performing complex event processing (CEP). A variant of streaming SQL with extensions for processing a collection of events over periods of time is used for this activity. This enables users to set up a table with the necessary fields and create a block that consistently reassesses the data as it is refreshed.
Furthermore, Ballerina is designed to be accessible without a server. The language is already supported by various serverless platforms, such as OpenWhisk, an open source, distributed serverless platform that performs functions in response to any sized event. WSO2, the open source technology provider that developed Ballerina, runs an OpenWhisk service that they call WSO2 Serverless Solution.
How does Ballerina work?
As a compiled, type safe, concurrent programming language, Ballerina's code is gathered into bytecode and then run in a virtual machine (VM). The artifacts are put into containers. Ballerina uses a concurrent, non-blocking model in which different workers are assigned to outbound work and others handle inbound work. This eliminates the possibility of thread blocking or performance lags.
Ballerina is neither an object oriented language (OOP) nor a functional one. While the language has objects, the development methods are not completely OOP-based. The design principles use a sequence that diagrams concepts, including declarative elements that are not purely OOP. In Ballerina, both objects and functions are first class concepts, giving developers the ability to choose the best option based on their requirements.
Network events in Ballerina are native. Developers are able to create service endpoints and clients that include full annotation, or documentation, and filters. Also, since popular data formats -- like JSON and XML -- are their own data types, developers are able to program directly against the data.
Ballerina's standard library includes both the normal standard library level functionality as well as a library of network protocols, data formats and interfaces and authentication/authorization standards. These two parts make writing secure, distributed applications with Ballerina easier than writing with other languages.
Benefits of Ballerina
In the past, developers either had to choose heavy, complicated server products for controlling integrations, or use a general purpose language with a framework that varied for each language and objective. There was no way to find speed with rapid code development that ran micro integration servers for message brokering, transaction coordination and service hosting.
Ballerina endeavors to combine the promptness of a type safe language with the syntax of an integration sequence diagram. This combination creates binaries that insert micro engines that perform inline integration semantics like mediation, orchestration and transformations. Tests have shown that Ballerina's technique can offer 20,000 to 25,000 transactions per second on basic hardware, making the language about fifty times faster than Python. This speed creates higher efficiency and cost reductions.
The Ballerina language is based on a visual representation so that everyone can use and understand it. Sequence diagrams build the integration code as it is created. The language requires minimal usage knowledge, unlike other complex languages that can only be employed by experts.
Ballerina is also flexible. There is a constantly growing amount of users adding to the code base. This is because it is easy to take advantage of the functionality of other programs due to Ballerina's API. Plug-ins coded with Ballerina can be used with IDEA and Vim. It is also possible to create integrations using the sequence diagrams. Furthermore, Ballerina makes it easier to write microservices that integrate APIs as well as turn any function into an API endpoint, making each function a stand-alone microservice. This establishes the use of a single semantic domain for integration operations and allows the generation of a Swagger file that can work as an open API gateway.
History of Ballerina
The Ballerina language was built by WSO2, an API management software company that wanted an easier way to integrate microservices for its own purposes. WSO2 made the first production-grade release of Ballerina in May 2018. The language powers WSO2’s API microgateway engine. Early contributors to the Ballerina ecosystem include Google, Bitnami, Honeycomb and Apache OpenWhisk.
The title 'Ballerina' comes from WSO2 CEO and founder Sanjiva Weerawarana’s admiration of how tightly coordinated ballets are and how this coordination creates a graceful flow.
On February 21, 2017, Ballerina became a public open source project. Throughout 2017 and early 2018, developers worked to redesign the language based on the feedback received from the public. The current revision is pre-1.0.