BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Ballerina - An Open Source JVM Language and Platform for Cloud-Era Application Programmers

Ballerina - An Open Source JVM Language and Platform for Cloud-Era Application Programmers

This item in japanese

Bookmarks

Open-source technology company, WSO2, has released Ballerina 1.1.0, an update to their programming language with new features including: the new Ballerina Tool, enhanced IDE support for VSCode and IntelliJ IDEA; and improved performance in runtime type checking, and creating and accessing maps, arrays and records.

Ballerina is an open-source programming language for writing network distributed applications. It is a relatively new player among the non-Java JVM languages such as Scala, Groovy and Clojure. The release of Ballerina 1.0 in September 2019 was an effort three years in the making, after WSO2 decided to create their own programming language in their efforts to improve their enterprise service bus (ESB).

Early in its development, the Ballerina team attempted to implement their own virtual machine, but experienced performance bottlenecks. Known as the Ballerina Virtual Machine (BVM), this VM executed Ballerina programs by interpreting BVM bytecode emitted by the Ballerina compiler. However, the Ballerina team ultimately decided that the BVM, despite having been implemented in Java, was not ready for production use, and decided in favor of including a compiler that targets the JVM with the release of version 1.0.

As a platform for cloud-era application developers, Ballerina promotes networking as a first-class concept into the language with the introduction of fundamental, new abstractions of client objects, services, resource functions and listeners. Developers can now build resilient, secure, and performant network applications that address the fallacies of distributed computing.

Lakmal Warusawithana, senior director of developer relations at WSO2, spoke to InfoQ about Ballerina.

InfoQ: What was the inspiration to create Ballerina?

Lakmal Warusawithana: WSO2 was founded with the vision of "making integration better." Our team has worked on thousands of integration projects. The Enterprise Service Bus (ESB) is designed to make integration simple by using a domain-specific language (DSL). The ESB's higher-level abstractions, like mediators, endpoints and proxy services helped to create a solution for enterprise integration with a meaningful graphical view that wouldn't be possible with a solution that was written in a programming language like Java, JavaScript or Node.js.

With our 15+ years of experience, we came across some complex scenarios that cannot be described by the DSL. Typically, these will end up by writing extensions with Java. In practice, this means that complex solutions are written as a combination of DSL configurations and Java extensions. This brings down the advantage of GUI-based integration projects because Java extensions are a black box as far as the ESB's graphical interface is concerned.

This creates additional complexity for many aspects of the software development process like the build, deployment, and debugging. ESBs are designed to work well in a centralized architecture where a single monolithic ESB controls the entire enterprise integration. It is an anti-pattern for modern microservice architectures and badly affects the agility and DevOps of enterprise integration projects.

These limitations led us to create Ballerina. The high-level goal is to create a programming language and a platform co-designed together to make enterprise integration simpler, more agile and DevOps friendly by including cloud-native and middleware abstractions into a programming language in addition to the expected general purpose functionality.

InfoQ: Please describe how Ballerina addresses the fallacies of distributed computing.

Warusawithana: With the emergence of microservices architecture, applications are developed by using a large number of smaller programs. These programs are mainly integration microservices. They interact with each other over the network and provide the application functionality. Now developers have to deal with all the fallacies of distributed computing in these smaller applications.

For example, developers usually implement these services by writing an explicit loop that waits for network requests until a signal is obtained. But if you use Ballerina to write a service, you can use the language-provided constructs and it just works. Network abstractions like endpoints, listeners, services, and remote methods are first-class language constructs in Ballerina. It makes dealing with a large number of smaller services a lot more convenient.

Ballerina services can have one or more resource methods where you can implement the application logic. A service can work in conjunction with a listener object. A listener object provides an interface between the network and the service. It receives network messages from a remote process according to the defined protocol and translates it into calls on the resource methods of the service that has been attached to the listener object. HTTP/HTTPS, HTTP2, gRPC, and WebSockets are some of the protocols that are supported out-of-the-box in the listener object.

Another key abstraction is the remote method, which is part of the client object. In Ballerina, a remote method is invoked using a different syntax from a non-remote method. A program sends a message by calling a remote method by using the protocol defined in the client object. The return value corresponds to the protocol's response. Since these remote methods are calling over the networks, we need to implement different resilient techniques in our code to deal with unreliable network behavior. Resilient techniques like a circuit breaker, load balancing, failover, retry, and timeout comes out-of-the-box in the Ballerina HTTP client object.

Ballerina does not try to hide the network in the application code. Network data types like XML, JSON, table, and stream are built into the language. Due to the inherent unreliability of networks, errors are an expected part of network programming. Ballerina's approach is to explicitly check for errors rather than throw them as exceptions. It's pretty much impossible to ignore errors by design.

Distributed systems work by sharing data between different components. Network security plays a crucial role because all these communications happen over the network. Ballerina provides built-in libraries to implement transport-level security and cryptographic libraries to protect data.

In addition to this, Ballerina has an built-in taint analyzer in its compiler. Taint analysis is designed to increase security by preventing any variable that can be modified by user input. All user input can be dangerous if this isn't properly checked. As a result of the taint analysis mechanism, the Ballerina compiler identifies untrusted (tainted) data by observing how tainted data propagates through the program. If untrusted data is passed to a security-sensitive parameter, a compiler error is generated. Since the taint check happens at the compiler stage, the programmer can then redesign the program to erect a safe wall around the dangerous input.

Earlier, developers simply wrote their program, built it and ran it. Today, developers also need to think of the various ways of running it, whether it be as a binary on a machine (virtual most likely), by packaging it into a container, by making that container a part of a bigger deployment (Kubernetes) or by deploying it into a serverless environment or a service mesh. However, these deployment options are not part of the programming experience for a developer. The developer has to write code in a certain way for it to work well in a given execution environment, and removing this from the programming problem isn't good.

Ballerina specializes in moving from code to cloud while providing a unique developer experience. Its compiler can be extended to read annotations defined in the source code and generate artifacts to deploy your code into different clouds. These artifacts can be Dockerfiles, Docker images, Kubernetes YAML files or serverless functions.

InfoQ: Please describe the concept of the sequence diagrams for programming. Is it simply a method to write code based on a sequence diagram? Or is there a way to generate source code from a sequence diagram and/or export a sequence diagram from source code?

Warusawithana: With our 15+ years of experience working with customers on thousands of integration projects, we saw that a sequence diagram was the best way to visually describe how services interact. This was the foundation for designing the syntax and semantics of the Ballerina language abstractions for concurrency and network interaction so that it has a close correspondence to sequence diagrams. Additionally, this is a bidirectional mapping between the textual representation of code in Ballerina syntax and the visual representation as a sequence diagram. The Ballerina IDE plugin (for example, the VSCode plugin) can generate a sequence diagram dynamically from the source code. The generated sequence diagram fully shows the aspects of the behavior of that function that relates to concurrency and network interaction.

InfoQ: How was the name Ballerina chosen for this new language and is there a significance to the name?

Warusawithana: At the beginning of this project, we did not have a proper name and we used a code name called NEL (New ESB Language). There were a couple of internal mail threads with more than 100 mails suggesting different names but we never settled on a single name. The name “Ballerina” was initially suggested by Manuranga Perera, lead engineer - Ballerina team, as enterprise integration and the interactions of components is similar to how ballets are coordinated and choreographed.

InfoQ: What's on the horizon for Ballerina?

Warusawithana: Ballerina is not a short term project. Ballerina is set out with grand plans to bring pretty much all enterprise middleware into a programming language. The current Ballerina release is based on the jBallerina implementation which provides a compiler that produces Java bytecodes as well as an implementation of the language library and the standard library. We are planning to do an implementation that compiles directly to native code and the Ballerina team has started to look at using LLVM for this.

As per the short term goals, in 2020, the Ballerina team is planning to add the following features:

  • Language integrated query
  • Streaming query
  • Better concept of tables
  • Better database integration
  • Transactions including distributed transactions between Ballerina programs
  • Locking
  • Dataflow style data mapping

InfoQ: What are your current responsibilities, that is, what do you do on a day-to-day basis?

Warusawithana: In my current role, I am focusing on evangelising and building developer relations around the Ballerina community. I spend most of my time working on evangelism presentations, speaking, writing articles, and building ecosystems around Ballerina. Previously I have contributed to the Ballerina spec, design, and architecture mainly on Docker and Kubernetes integration with Ballerina.

Getting Started

There are two valid entry points for a Ballerina application: a method, main(), which runs as a terminating process; and a hosted non-terminating process, service.

A GitHub repository containing short examples demonstrating how to use both entry points is available to get started. Ballerina also offers numerous examples and a repository of reusable modules.

Ballerina plugins for both IntelliJ IDEA and VSCode are also available for developers.

Resources

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Ballerina ... you must've seen her ...

    by Cameron Purdy,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I took a look at Ballerina about a year ago. It's very exciting to see people working on new ideas for how to simplify development.

    Kudos to the WSO2 team for tackling a hard problem, and sticking with it!

  • correct examples link

    by Lucian Ciufudean,

    Your message is awaiting moderation. Thank you for participating in the discussion.

  • Re: correct examples link

    by Michael Redlich,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hi Lucian:

    Thanks for catching that. I certainly appreciate you letting me know. I just updated the news piece to reflect the new link.

    That link worked when I published the news piece, but it would appear that they've changed it to match the pattern of other links.

    Mike.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT