Conf42 Cloud Native 2023 - Online

Ballerina - A Cloud Native Programming Language

Video size:

Abstract

This talk will discuss code-to-cloud aspects of the everyday developers using the Ballerina programming Langauge. It is a fully open-source language with community support. This talk will be done with a real-time demo of language usage.

Summary

  • Ballerina programming language is an open source programming language. It makes it very easy to write network based application for the cloud. WSO two is a leading technology provider in the domains like integration, identity and access management.
  • Ballerina is a general purpose programming language. It is specializing in the domain of integration and cloud based problems. It provides the right set of abstractions and tools to make it easy for the developer. The current major version is Son Lake. We released it in 2022.
  • Ballerina is a data oriented programming language. It provides different support for different protocols and especially different data types. The language makes it easy for application developers to write services. Developers must focus on the business logic, not anything else about the network.
  • Every ballerina program is automatically observable by any open telemetry tool. You can connect to external systems like Prometheus, Grafana, Yeager or any other login platforms. Ballerina is designed carefully not to have tight coupling with the Java or JVM. It has support for many cloud connectors and cloud deployment capabilities.
  • So in today's session I covered in detail about features of the language. There are so many capabilities that you can try out. My request is try the language and try to use it in your applications and share your feedback with us.

Transcript

This transcript was autogenerated. To make changes, submit a PR.
Hello everyone, welcome to the Conf fourty two and the ballerina programming language session. In this session I'm going to discuss in detail about ballerina programming language, which is an open source programming language. It makes it very easy to write network based application for the cloud. Before going to the details, let me introduce myself. I'm Anupama Pathirage, currently working as director of engineering at WSO two. WSO two is a leading technology provider in the domains like integration, identity and access management, API management and so on. Ballerina language is designed and implemented at WSO two, but currently it's driven by the open source community as well. WSo first, let's look at what are the problems that we are facing today and where we are in terms of application development methodologies. If you look back the history a little bit, in many decades ago we had systems like mainframe systems with legacy and centralized applications. And then gradually client server based distributed applications came into the picture. And after that, with the improvements in the Internet and cloud based technologies, things has evolved a lot. And the way that we are writing programs and the way that we are designing things has evolved a lot. And then as developers, everyone has to adapt to these changes. And if we look at how we approach the given problem or when we are developing solution for a given programming problem, in the old days, we considered libraries as a unit of logical components, as that is the component that we are dealing with on the systems, which are very much centralized. But in nowadays, it's unavoidable to have communication links between different systems. That means we have to talk to different endpoints and get some data and process them and send them over wire to some other place. So that's a normal thing. And that means APIs are becoming the natural unit of execution, natural unit of applications these days. So if you look at any kind of application, it usually has a front end as well as a back end. So back end means in nowadays applications, it doesn't work on its own. It has to talk to many different systems and it has to extract data, process data, and then move it out from that system to some other place. That means it involves with many different network protocols, many different data formats, so it's unavoidable to deal with that complexity. And also, in today's world, there are so many languages, programming languages, which can handle great front end stuff as well as backend things. But although there are a lot of such languages to develop backend applications, it is not that easy when we talk about this problem, because API integrations and this integration problem is complex due to the network interactions as well as different data types and also different communication paradigms. So that is the problem that we are trying to solve because we observed this problem or this hurdle for the developers for a long period of time. And if we look at the different technologies, integration products and technologies in one side, for example ESPs, e, AI, BPM, those things are not that much cloud native and those are giving proper or great functionalities, but maybe not the ideal solution for the cloud. And on the other hand, we have general purpose programming languages and frameworks which are very much flexible, but at the same time they don't give the right set of abstractions to deal with the problem in this domain. So that is why we have introduced another language called ballerina to deal with those two different ends. It is providing the capabilities like any other integration product and technologies, as well as it gives the flexibility of the programming language to deal with the complexities of the application developers while providing the right set of abstractions. So if I talk a little bit about the history of the language, we started it in around 2016, but real idea came into the picture even before that, maybe around 2010, because in WSO two we developed application for these domains and we observed the problems and we identified the blockers that developers are facing. So then we thought a programming language would be the ideal thing to solve this problem. It's a general purpose programming language, and if you look at the syntax, you may feel like it's familiar because we have CC plus plus family syntax in the language, but at the same time it is specializing in the domain of integration and cloud based problems. It provides the right set of abstractions and various tools to make it easy for the developer and it's open source project which is given by the open source community. We started in 2016 and it went through multiple iterations because we have our own compiler and platform around that to make it a complete thing. And we released our first version in 2019 and the current major version is Son Lake. We released it in 2022 and right now we are developing many features improvements over the sown lake as well as we are doing separate tracks to deal with other things like different language aspects or major additions to the spec, as well as native compilation to support native compilation for the ballerina language. So that's the status of the language. And let's look at what are the unique features of ballerina, which makes it easy for the application developers. One main thing about programming is there are many different programming language. It can be different kinds, data oriented, object oriented, function oriented and so on. In Ballerina we consider it as a data oriented programming language, because if we look at any programming piece of program which works with many different entities or endpoints, usually what we share is data. In earlier days we share code over the network, like in the RPC style of applications, but we no longer do that because of the security concerns and other things. Instead we move data around. That means we need to have better ways of representing data in the network as well as the data in the memory. So in Ballerina we designed in a way that we emphasize the plain data concepts that is independent of any code and protocol and the ways of processing, especially how we can access data, how we can transform data. So those things should be very easy and intuitive for the application developer. And at the same time in ballerina we have different support for different protocols and especially different data types. For example JSON XML. Those are primitive types in the language like string, int, flot like in other languages. And also ballerina language provide query like syntax. If you check this code, you can see SQL like syntax here. This is to process the data which are coming from the wire. You can see the data received via the wire is assigned to memory in memory type that we defined in the application level and then we process it using query like syntax. It is very easy because we don't have to write complex logic to get lot of filtering as well as processing of the data. And then we provide network oriented capabilities because network is the primary thing when we talk about integration and cloud native applications and type system type system is playing a key role here because we have to deal with the data on the wire as well as data in the application or memory level as well. So here you can see we are talking to endpoint and talking to endpoint is very easy in the language. The concepts of the client service are very much intuitive and then the return type represent the output from the network. Endpoint usually JSON XML type of responses. And we can map it directly to a data structure defined in the application without doing explicit casting or any other processing. So that eliminates very much boilerplate code if you want to convert things. And it support well known data formats and converting and accessing is very easy. And other concept is service. Service means similar to retrieve data from other endpoints and services. We have to serve data as well. So ballerina service concept gives you a very much easy way to write services. A service concept is a first class thing in the language and depending on the listener that we are binding to, that it act as a different service type. If you can see here we are attaching HTTP listener to this service. That means this will act as a HTTP service. So based on the attached listener service will behave differently because here you can see we are developing HTTP listener and you don't need to worry about internal network details. All the things are handled by the listener and the service itself. What you have to do is implement the resource functions to match with the requirement of the service. So in HTTP world it's usually get post delete those kind of operations and we can write resource functions for these things. You can see get here post here. Those goes very close with the HTTP world and what you have to mainly focus on the business logic, not anything else about the network or the underlying complexities. And it returns the data types in the language itself or the data types that you have defined, and then the listener will handle it internally when it's returning to convert it to the proper format, the default formats and so on. So here also we support two different interface styles. You know, in RPC style we usually have remote methods. In that case within the service you have to define remote methods and restful style like HTTP graphql. We have to write resource functions. So what the developer has to do it is focus on the business logic because the right level of abstraction is provided by the language to deal with the community of developing the services and the boundaries and how we handle things. And also concurrence is playing a key role here. In network applications, concurrence is kind of unavoidable thing and we provide different concepts and support even during compile time to guarantee the compiled time safety as well as runtime, concurrency, safetiness and similar to the services, clients are also very much important. Clients means we need to invoke other endpoints of different types of protocols. So language provides support for different clients and depending on the client, client is a language concept and depending on from which protocol that you are, depending on which protocol that you are using to access the client, we can define different type of clients. It can be GRPC, Websocket, graphQL and many more different protocols. So creating a client is easy. You can provide additional parameters if needed and also invoking the functionalities or get the details or get the response out of it. Also very easy. The syntax for calling or invoking an endpoint is like this, and also you can bind data very easily the response data. So then that means with all these things developers can focus on real business logic and they can then take more time to focus on that and another concept is when we think about enterprise application, concurrency and reliability is very much important because we have to always make sure our applications are behaving in a reliable way. And also in the integration world, concurrency is mandatory thing. So like any other language, we provide concurrency handling constructs. We have asynchronous function calls, workers and strand concepts, which provides a logical thread of control. And all these things are there. At the same time, ballerina guarantees or provides many mechanisms to ensure the concurrency safetyness during the compile time itself by means of different mutability concepts. So those things are a little bit complex and difficult to handle in a small session like this. But Belna tries to be proactive when giving the warnings and other errors related to concurrency problem without waiting till the runtime. And also reliability. That means usually, for example, transactions plays a huge role in enterprise applications. We need to guarantee the atomic operations. And in ballerina, transaction is a first class thing, and it's a syntax by the syntax itself, it defines the transaction boundaries. And you can write your business logic within this syntax block, and then it guarantees the atomic operation of the execution of the internal code. So likewise it tries to address the problem of the problems that integration developers are facing. And there are many more such concepts like HTTP resiliency protocols and how we handle things like that. And another important thing is usually when we design an application, we write or withdraw diagrams to explain things and to understand things and to visualize things properly. But in ballerina we don't have to do it explicitly because it provides different level of diagrams to make it easy for the developers. So every piece of program that you write, there's an equivalent diagram which is automatically generated. So this is a program in the left side, and in the right side you can see the diagram which is automatically generated. And also the important thing is we maintain the parity between the code and the diagram. That means if you change something in the code, it appears automatically in the diagram. And if you change something in the diagram, diagram is editable. You can see these plus points where you can add anything that you can do in the code side using the diagram, and it will generate the code if you add things on the diagram side. And when you look at the code, sometimes you can't identify high level view, what are the interactions, which is very important in integration kind of application. So here you can see we are interacting with two different endpoints. One is GitHub and other one is Google sheets. And then we are getting responses and do some processing. And this is the diagram generated in the VS code plugin. You can install the VS code plugin from the VS code marketplace and this gives the diagram view automatically. So that's very much helpful when you are talking to some other stakeholders or if you are discussing among the developers about the application, or if you are trying to understand the application overall. Big picture. So this is like a sequence diagram where we have vertical lines which represent each thread of execution as well as different endpoints. And these horizontal lines represent the interactions between those different endpoints and the actors. And those are the not only diagramming features that we have in the Belarna. We provide different level of diagram capabilities. One thing is the sequence diagram, and there are so many other things including architecture diagram as well. If you are developing a complex application which involves multiple components or services or multiple modules, then it gives that view as well, like high level view on how different components are interacting with each other as well. What are the dependencies and how they are in working different application. And another thing is the data mapping feature. So usually when we deal with data coming over the wire, we have to process them and especially we have to convert them into different formats or different data types. So as you can see here, language provides the capabilities to map in a very convenient way, because if you have to write all the logic of mapping in hand, it's very difficult task if you have large payloads, but in this view you can easily drag and drop or connect the different fields from opensource type to the target type. And also in between you can type whatever the custom logic in mapping. Sometimes you may have to do some intermediate step or calculation before mapping, then ballerina support that as well. So along with all these diagram capabilities, it's very easy to write programs even if you doesn't know much about the language. And then another feature is built in observability. Every ballerina program is automatically observable by any open telemetry tool. And it has three main areas like matrix tracing and login. And you can connect to external systems like Prometheus, Grafana, Yeager or any other login platforms to visualize or to observe the behaviors in the runtime. So that capability is built into the language. It's just a matter of enabling or disabling it, and it gives the support to connect with these tools. And another important thing when it comes to the cloud is how easy it is to develop or using your code or deploy your code in the cloud. Usually the practices developers are developing it and it hand over the relevant artifacts to the deployment engineers and then do all the artifact generations to the cloud environment and the deployment environments, and then do the deployment. But in ballerina, since it's focused on the cloud deployment most of the time, we provide easy ways to generate the deployment artifacts as well. Here you can see Bellbuild command. This is a simple hello world program or service written in ballerina. In the Bellbuild command, we can provide additional argument called cloud and with the parameters of the environment that you want to deploy. For example here, this example, it's kubernetes. It can be Docker things like that. And when you provide that, it builds or it generates the artifacts that you need to have to deployment as well. For example Docker files as well as Kubernetes artifacts including service deployment and other YAML files. So then when you do that, what it does is it extracts some of the parameters and other things from the code itself. And also you can config things. Sometimes you might need to improve the behaviors by providing more memory and other things. You can provide those in config ToML to change the generated artifact values. And then based on all these things, it will generate the cloud artifacts where you can customize and deploy if you need. So that is about making it easy for the cloud. And that is not only about that, because since it's a full platform, it has support for many cloud connectors and cloud deployment capabilities and different ways to connect different cloud providers, things like that. So one other important thing is right now, ballerina is written in Java. That means compiler is written in Java and it generates JVM bytecode. And also it provides Java interoperability because of that. So that means if you have a piece of code written in Java, and if you want to invoke it using a ballerina code, you can easily use the Java interoperability capabilities so that you can link that Java code into the ballerina code. And also, although it's written in Java and generate JVM bytecode, the semantics of the langauge were carefully designed to be independent of the Java and JVM. Because our target is to create another implementation which generates a native bytecode, that work is currently in progress. That's what we called N Valorina, and also recently we introduced a native flag which generates gralvm native executables when building the ballerina project. So ballerina is designed carefully not to have tight coupling with the Java or JVM. In future we will provide more native kind of artifacts as well. And also, ballerina is not just a language, it offers a full platform, especially the Vs code plugin which provides all the capabilities that I have mentioned including source and graphical editing, debugging and diagram generation for like architectural view and other things. And it provides the capabilities that any other vs code plugin provides for any other language, but at the same time with the diagram aspects and deployment aspects it provides some additional features as well and also generating or working with the schemas like Open API, GraphQL, GrPC. Those are very much easy and to generate the API documentation we have commands and also test framework is similar to most of the language just but with service mocking and other stuff too. And Belna contains standard library and extended library which provides support for many different protocols like HTTP, GrPC, Websocket as first class things. And also we have extended library with a lot of connectors for different APIs as well as SaaS applications. So Balna Central is a centralized place where you can host things if you want to share your code with other developers, so that if others can benefit from your code, you can package it and share it using ballerina central, our module sharing platform which is free to use for anyone and then for other features, runtime features especially like observability and DevOps capabilities. Balana language provide better features. Also WSO two is providing another offering which we call Choreo SaaS application development platform which makes it really easy to develop, deploy, manage and observe the applications in the cloud. So it's not directly related to Ballerina, but at the same time it will give you more features and more capabilities if you combine ballerina and Corio together because it addresses the problems of the entire application development lifecycle. So in today's session I covered in detail about features of the language, but it is somewhat high level list because in language there are so many capabilities that you can try out. And so my request is try the language and try to use it in your applications and share your feedback with us. We have a community around us, opensource development community in various platforms including Discord, Stackcore, flow, Twitter, GitHub and so on. So feel free to join with us if you're willing to contribute to the language as a developer as well as if you want to use it in your applications. So that's about some high level overview about the Ballerina programming language. Thank you very much for joining today's session and hope you will enjoy the rest of the sessions as well.
...

Anupama Pathirage

Director Of Engineering @ WSO2

Anupama Pathirage's LinkedIn account Anupama Pathirage's twitter account



Awesome tech events for

Priority access to all content

Video hallway track

Community chat

Exclusive promotions and giveaways