Ballerina: Cloud-Native Middleware as a Programming Language
Anupama Pathirage40:182022
A language where the sequence diagram and the code are the same thing
Change the code and the sequence diagram redraws itself; edit the diagram and the code rewrites. That is one of the bets behind Ballerina, an open source language WSO2 built for integration-heavy, cloud-bound services. Anupama Pathirage, a Director of Engineering at WSO2 who has worked on its compiler and runtime, live-codes a book search service against real APIs. Can a language really absorb the plumbing developers now write by hand?
Watch a live build of a REST service, from network calls to generated Docker and Kubernetes files
Anupama Pathirage, Director of Engineering at WSO2, explains why integration-heavy, cloud-bound applications call for a language with network concepts built in, and introduces Ballerina's design and key features. She then live-codes a REST service that calls external APIs, maps JSON to typed records, renders a sequence diagram and generates Docker and Kubernetes artifacts.
“So cloud development is not something that we can avoid.”
“That means if you edit the code, diagram will be auto-generated. And if you edit the diagram, code will be generated.”
What you will learn
Explain why integration-heavy cloud applications need network abstractions, a network-aware type system and built-in concurrency support.
Build and call HTTP APIs with Ballerina clients, services and resource functions.
Handle network errors with union types, type narrowing and the check keyword instead of exceptions.
Apply open records to incoming data, closed records to responses, and query syntax to transform data.
Generate Docker and Kubernetes artifacts from code and keep code and sequence diagrams in sync.
Key takeaways from the speaker
Latest trends in integration and cloud native development
Open source development and its importance
Art of programming language development
Details
Level
Intermediate
Format
Tech talk
Technical depth
Practitioner
For
Early career, Mid-career, Senior individual contributor
Length
40:18
Published
July 2022
Questions this talk answers
Why did WSO2 build a new programming language?
Modern applications are integration heavy and need network abstractions, a network-aware type system, protocol support, concurrency, cloud friendliness and visualization in one platform. Without that, developers rely on third-party tools.
Is Ballerina a JVM language?
No. jBallerina is written in Java, runs on the JVM and is production ready, while nBallerina compiles natively with LLVM and was still in progress.
How does Ballerina handle errors from network calls?
Instead of throwing exceptions, functions return errors as part of union types. The check keyword passes errors up, and an HTTP listener turns a returned error into an HTTP 500 or relevant error.
How does Ballerina help move code into the cloud?
Building with a cloud option such as Kubernetes generates the Dockerfile and Kubernetes YAML descriptors automatically, with optional configuration in a Cloud.toml file.
How can developers get involved with Ballerina?
Through its Slack and Google group, and by contributing to the free, open source code on GitHub.
About this talk
Ballerina is a cloud-native open source programming language tailored for network awareness and microservices development. The language is uniquely positioned in the cloud-native domain and focuses on boosting developer productivity in highly disaggregated architectures.
With the traditional programming languages, solving Integration problems and dealing with the complexities of distributed programming models is not that easy. The inherently complex nature of integration problems and infrastructure requirements of cloud-era applications can challenge the success of digital transformation projects.
Ballerina is an attempt to build a modern, industrial-grade, general-purpose language optimized for integrating and writing network services and applications. One of its key objectives is to simplify micro-services and integration-heavy programming by offering network primitives within the language. The network-aware type system, first-class support for network services and resources, distributed transactions, stream processing, cloud support, sequence diagrammatic syntax, etc., in Ballerina, simplifies building and deploying cloud-native applications. Also, Ballerina has built-in support for various technologies and protocols such as HTTP, gRPC, GraphQL, WebSockets, NATS, Kafka, OpenAPI, etc. This makes it a much more intuitive experience for the developer.
Ballerina Swan Lake version, which was released in February 2022, has introduced significant language features. This talk will focus on the key traits of the language with a live coding session on real-world examples of how it can boost developer productivity.
Why integration-heavy apps need a new language (86 s)
Code and sequence diagram in one-to-one sync (47 s)
Returning errors instead of throwing exceptions (54 s)
Hello everyone. Thank you for joining for today's session. It's about Ballerina, a new programming language that we have developed at WSO2. So in this session, I'm going to cover some details about the language and I will do a quick demo as well. But before moving to the discussion, let me quickly ask a question from you. So if you see this image, there will be a lot of things coming to your mind if you are coming from the development background. So let's say you are coming from a software development background. There are so many things that you know about programming language.
If someone is asking you what's the best programming language to learn or what is the best programming language for a given scenario, then there will be thousands of questions in your mind. There are so many different programming languages and also so many different types of programming languages. So selecting one is not that easy. So that is where the problem started. So and then let's see what are the newest strengths and the challenges as well to this software development or application development process, especially for developers. So this is taken from the IBM Cloud Native Development Report.
So there it says majority of the application, new application that is out of like 55% of the new application will be directly into the cloud. And also existing applications like non-cloud applications, we will have to move them majority of them to the cloud very soon. And even existing cloud applications, we will have to do some changes or customizations or add new features. So cloud development is not something that we can avoid. So it's a latest trend and also it has certain very, very high level of advantages, but it will introduce some challenges as well. So in this session, that's what I'm going to mainly cover, uh, why we need a new programming languages, uh, language and what is Ballerina, obviously some key features of Ballerina. I will do a demo, a live coding demo to develop a rest
service using Ballerina. And finally, I will let you know how you guys can, can connect with Ballerina to contribute to the Ballerina open source development. So if you look at the normal application development process, if you are coming from the software development background, you are, you should be very much familiar with this. So usually what we do is we gather the requirements and then, uh, we have to, uh, design the systems and then we have to implement, test it and build the system, uh, package it to the required artifacts, and then finally deploy it. And in the middle, we have some documentation steps as well. That's the usual process. But when it comes to the cloud, it's not ending there. There can be so many other steps, continuous steps where we have to focus on. So
out of them, uh, so the application development process, usually we have to think about, uh, cloud aspects as well. Uh, that means we have to build some of the Docker files and write deployment descriptors and also API management and security that plays a huge role there because we are developing something, uh, which are interacting with the network. So it's not that easy to manage security and also the access to it. Also the scaling and performance that also having a huge factor here because performance is very much important nowadays. And also observing, like we need to analyze the usages and analytics.
And based on these factors, we have to redesign the application sometimes. So redesigning means we may have to adjust some of the things we have to re re implement the things or by optimizing, or maybe we will have to do some, uh, full code revamp as well. So that is a continuous process that we are talking about. So the next thing is, uh, why we need a new programming language. You know, there are many different programming languages in the world and, uh, all these programming languages are good at something, uh, specialized in some areas, some general purpose languages. So everything is there, but the problem is now modern applications are good, uh, for general purpose programming language, general purpose applications, but sometimes the modern applications are very much, uh, integration heavy. That means we
have to interact with multiple endpoints. And also that means interacting with network is something that we cannot avoid. So we need better network abstractions and also better support for network data or the data representation. Usually the data representation means we communicate with multiple different, uh, endpoints. And that means we need to have a good support for, uh, data representation, transforming them, and also maybe, uh, convert them into different types or process them. So that's very much needed. And also the network aware type system, uh, to do all these things, we should have a very rich type system, which is aware about the network as well. And then there are so many different network protocols. So we need to think about that as well. So the network protocols means, uh, grpc, web socket,
http, web sub, there are so many protocols like that. So we need to have first class support for them as well. Another important thing is we need to think about the concurrency aspects, uh, integrating with multiple systems. We, we can't forget about the concurrency network interactions are inherently concurrent. So we need to, uh, have better support for concurrency as well. And obviously, as I said before, cloud friendliness, which we can't avoid, that means developers should be able to bring their code into the cloud very easily. And then the visual representations, usually when we develop a sophisticated application, it's very hard to, I didn't understand the code by just looking at the code. So if we can have some better visualization, that will be a great help. And finally, it should be a complete platform, not just
a language. That's also very important because if it is just a language, and if it doesn't have other support like cloud support and other protocol support, then we will have to look for third party tools and other, maybe other, other supportive in ecosystem tools. So that is also kind of a problem for the developers. So that's why we thought we needed new programming language. So the motivation was we are from WSO2. I'm from WSO2. We started this project in 2016, and it's a general purpose programming language, but it is specialized in solving integration and cloud based problems. And most important thing is, although it started and maintained by the WSO2, it's an open source project and driven by the open source community. So anyone in the world can contribute and use it without any charge. And also,
this is a kind of a quick highlight of our timeline. We started in early 2016 as a synapse, like as a replacement for existing synapse based applications at WSO2. And then it went through multiple iterations, development iterations. And finally, we released a first version of it at 2019. And in 2022, February, we released Swan Lake version. And also in the future, there are so many other plans to enhance existing implementation as well as do the support for the release version. So that's a high level timeline of ballerina. So then, since I gave some background, let me quickly go through what is ballerina. So when it when we say ballerina, what will go what goes to your mind is some kind of a dance.
Actually, it has some clear connection, connection with the dancing because we derived that name. Dance ballerina dance means it's kind of some synchronization dances how to interact together, and they have their own specific role to play. And they have to work together as a team. So that's where the choreography come into the picture. And when we when it comes to networking interactions, it's very important. The relevant communication is happening on time as planned. So that's why the name and other than that nothing to do with the dancing. Okay, so the language is not object oriented, I would say because language has object concept and it has objects. That means that if you want to associate some behaviors to the data, objects are there, but we don't need to use it all the time.
Sometimes you might decide, okay, I will just use functions instead of objects. And that has the flexibility to use objects or functions based on the requirement. And also, our primary focus is on the data, that is pure data, which is the network transmitted data. So we should be able to represent, describe and communicate data very easily. And another important aspect is a compiled language, that means not like interpreted language that at the compile time, we will generate things. And also, it's flexibly typed, that means usually statically type languages are too rigid, and dynamically type languages may be too they are not that strict. But at the same time, there can be some type related issues.
So Ballina stays in the middle, that means we do some checks at compile time. And we do we delay some of the checks into the runtime. So we stay in the middle, depending on the different situations. And also, concurrency language has first class support for many different concurrency aspects. And it will help to write a network interactive program very easily. And other important thing is Ballina is not a JVM language. It has two implementations, actually, the first one that we talked like, the one that we released already is what we call J Ballerina. It is written in Java to run on top of JVM. But this is the first implementation to prove the language, but it's production ready. And anyone can use it for the
production applications. Then we need to remove these Java bindings. That's why we call it N Ballerina. It's compiled using LLVM. N Ballerina means native Ballerina. It is generating the bytecodes directly into the platform architecture. So that project is in progress. And we will release in maybe one year, one and a half years of time. So let me quickly go through some of the key features of Ballerina.
So as I mentioned before, it provides better network abstractions. Usually network abstractions means if you are interacting with network, either we have to connect to some other endpoint as a client, or we have to provide some service to the clients. So if we are talking to another endpoint, that means we need a client. Client concept is coming from the language. And here you can see HTTP client. And HTTP client is coming from the standard library, HTTP module, but client is a language concept. And it has get, post, delete, such HTTP verbs, so that we can easily connect to another endpoint. And services mean, like this, you can see the syntax, it will listen on some port using a given listener. And listener is based on the
given protocol. There can be different types of services based on the protocol. This is just an example of HTTP service. And there are resource methods and remote methods. Resource methods means you can basically, it gives a data oriented view to access and manipulate data. And remote method means some network callable method. It will be useful for scenarios like GraphQL.
And as I mentioned before, we need network type system. That is one of the key features in Ballerina. We are dealing with plain data, we need to exchange plain data. And there's a specific type in Ballerina, what we call any data. And it can be directly serialized into JSON and many other formats in a very natural way.
So handling data is very easy if we are dealing with Ballerina code. And also Ballerina has structural type system, like records table, and maps arrays. So all these are there, we can convert between the different types very easily. So these are some of the common types, XML, JSON, table. These are some uncommon types that we have in Ballerina type system.
And other important thing is code to cloud aspect. That means how we can bring our code into the cloud. So usually developers will have to write the develop various YAML files, Docker files to bring their code into the cloud. But here Ballerina is providing easy way, we can specify the parameters to generate the relevant Kubernetes YAML files or Docker images, and it will generate all these things for on behalf of the developer. So it's just a matter of giving this command and putting some configurations if needed.
And then concurrency aspects, which is actually a huge topic. I won't be able to cover all these things related to concurrency here today. But in high level, we have asynchronous function calls. That means we can start a function asynchronously, and maybe we can wait for that output. And also we have the worker concept that represents a single strand of a function invocation. And strand concept, strand is like a logical thread of control assigned to a given worker. Likewise, so many concepts to handle these concurrency aspects. And it's a huge topic I'm not going to cover in detail today. Other important things like the reliability and the transactions. When it comes to transactions, we need to maintain the reliability.
And language itself provides syntax and semantics to transaction, commit, abort, and those kind of things. And so handling those things will be very, it's very easy if you are writing code in Ballerina. And finally, one other important feature is Ballerina provides sequence diagram. If you can see this, it has code in left side and the diagram in the other side. We have exact one-to-one mapping between the code and the diagram. That means if you edit the code, diagram will be auto-generated. And if you edit the diagram, code will be generated. I will show during my demo how it works. So I will quickly move to the next one. Ballerina is a platform. As I mentioned before, if it is just a language, that is not enough for
integration use cases or general purpose development as well. So we have the core language and also surrounding ecosystem as well. So this ecosystem is, it consisted of many things. It has a standard library for various protocols and utilities and different module support and also module repositories so that anyone can publish their code and share that, share that Ballerina code with others. And also the documentation system to document the source code, a testing framework, and also VS code plugin support with all these features so that developers can easily use all these features with the tooling support. So that is about Ballerina. Very quick overview in high level. Let me quickly show you some of the most popular modules in Ballerina.
This is not all the modules, but some part of the modules in the Ballerina center. We have different protocols support, HTTP, UDP, email, gRPC, GraphQL, and so on. And also Docker Kubernetes support and any other cloud functionality support and also SaaS application support and many utilities. Likewise, there are so many different protocols, utilities, and SaaS vendor related modules so that developers can get their work done very easily. So in high level, that's about Ballerina. Let me quickly go through the demo as well. I hope since this is a live demo, I hope it will run smoothly. Let's see how it goes. Before moving to the demo, let me quickly give you some idea about what I'm going to present today. Here, I'm going to search for books. Let's say users are willing to search for a given book by the title and
then they want to return the ebook versions of it. And also they need to see whether there's an associated move with that title. So that what I'm going to use is I'm going to create a service called NovelService and it will accept the user request. And in the background, it will go to the Google Books API to get the book details and also it will query Movies API to get the movie details. And also we had to do two requests here because in this API, first it will return an IDE for the given name. And then based on that ID, we have to fetch the data again to get the more details. So that's why there are two codes. So this is kind of a flow that I'm going to follow. I will do some coding and I will try to save
time by copy pasting some of the codes as well. Let's proceed with the demo. So I stopped sharing for now. Let me share the full screen again so that you can see the entire source code and everything. I hope you all can see my screen. Let me use my terminal here. Here I'm using Bell command. Bell is the Bellerina's build system and package manager.
I'm not going to use terminal for a long time. I'm just creating a new package. Bell has support for various other commands to various phases in the development process. And also it has package-related commands. Here I'm going to use bell new command to create a new package. So I'm using bell new novel service. So it will create a new package called novel service. So let me open it in vscode using the code command. I have already installed the vscode plugin and vscode application and ballerina plugin on it. So what it created is a main file. This is a regular main file that you see in any other language. It's just printing the hello world as the output. And I'm not interested in hello world here actually. I'm going to define a service. So let me delete this entire code and let's start creating
a service. So to create a service what I have to do is let me get the support from code snippets in ballerina. I'm going to create a http listener. So I use a code snippet and I'm going to fill it. The service is about books. So I'm going to name the base part as books. And it created the http listener which is listening on port 0. Let me quickly change it to 1990. And service definition is good. It has imported http because this is based on http protocol. To visualize the functionality let's set the resource function as well. So resource function means it is a get method and also we have to provide the name.
Let's say search. And since users are providing the book title as the input parameter or a query parameter, I added that as well. So this is a simple resource. Let's return some value type from that as well. So usually, APIs are returning JSON. So since ballerina is supporting JSON, I'm returning JSON here as well. To test it, let's return some dummy value. I'm returning test data here. So that's all. Let's quickly run run this program and see whether we can see the output. So I'm running it using well run command.
And I'm taking another terminal just to create the curl request to test my service. Let's say it's localhost running on and on the port 1990 base part is books. And then search with the name with the query parameter. Let's search for the book called maybe woe and peace. For this place, I'm using these characters. Okay, everything is good. I'm sending the coil command and it has returned the test data. So everything seems good. Our first version of the service is working well. And now let's implement our scenario. That means we had to call the Google API. First, let me show you how it looks like. Here you can see this is the sample request. Search for the woe and peace title. And it returns a huge JSON. So we are going to return this JSON via our service.
In order to do that, I need a HTTP client now. So let's create an HTTP client. I'm going to name it as book EP endpoint. And I'm going to create it using new. And the base part is this. I'm just copying it from here. I'm putting it here. And all good. But you can see it's as a red line here. The problem is, what I'm returning is HTTP client. But the actual return type is client or error. This is because this is related to network interactions. And it can always return errors. This is a feature in Ballerina.
Instead of throwing exceptions like other common languages, we are returning errors. So that there are union types. The pipe means union types. And returning error means we have to check the errors. Whether the return type is an error or the actual type that we want. So to do that, we can use if condition. If book endpoint is error, we can simply return an error.
This is a dummy message. Or else, we can process the real endpoint. Since the union has two types, the first one is checked for the error. And with the type narrowing in Ballerina, now it is reduced to HTTP client. So we can directly use endpoint here. And we can use get method. So what I'm going to get here is, this is the query.
And I have to mention the title. Title is taken from the user input. So I'm concatenating the name. Name is the input that I'm getting as the input to the resource. It's all good. And I had to return something. Since it's returning a JSON, I'm returning books here. And since this is also a network interaction, it can return error anytime due to network unavailability or anything. So everything is good. No errors. But then in order to process this JSON, I had to use another if first condition. So that is very difficult or inconvenient. So we have introduced another thing called check. If you use check keyword here, that means we are returning the error at that point. So we don't need to have this union. We can
simply avoid that. But since we are returning error, we have to pass it to the calling function. So we have to mark it as this function will return JSON no error. That means by returning a result from the resource function, it means the HTTP listener will handle it and it will convert it into a HTTP 500 or relevant error. So we don't need this ifs block anymore. We can simply remove it. And also here we can use check again to eliminate this union error type. It's all good. And let me format the code a little bit. And instead of this test JSON, now since we have a JSON in hand, let's return that JSON and see whether we can access it. So let's rerun the program. It's running and
it will take a bit of time to run. Yes, everything is good. And I'm going to use JSON pretty print tool to format the output. Let's invoke the API. Okay, we got the response. This is exactly the same response that we saw in the browser. So it called the Google API and return it as the output of the Ballerina service. So this is the first part. Actually, we don't need to return it as it is. We need to process it a little bit. So what we have to do is then process this JSON. Actually, we can process this JSON by just using the dot notation. But it has some limitations because we don't know exactly what what are the return fields and other things until the runtime if you are processing JSON. And if someone
wants to generate open API descriptions, it's very hard with like, it's not easy with JSONs because we don't know what is returning. So instead of that, what we can do is we can exactly define types for the given JSON. To do that, that means we need to create a mapping record, record type for this JSON. So by just looking at this, it will you will feel like okay, this is a huge JSON how we can create mapping structure.
So Ballerina is providing an easy way to do that as well. So it has a tool to convert and given basically paste the JSON as a record. So I copy the JSON response from the browser, and I pasted it. So it has created the all the required record types automatically. And it is a kind of big lengthy record list. But I'm not going to basically, I'm not interested in all these details. I'm interested in only a few fields. Let's rename this into books for the simplicity. And this to the items.
All good. And we have to rename this record as well. Okay, so I'm not interested in these two fields so that I can remove this. And even in the items, I'm only interested in, let's say some fields in the volume info and the self link, that is the link of the book. And in the volume info, again, I'm interested in a few fields, so that I can erase the other fields. In the volume info, let's say I'm interested in title, and average rating, and authors, only these fields. So that means I can safely remove all the other records because although that it is returning the data, I am not interested in that data. That is the concept of open record in ballerina. Basically being a bit liberal about what we are receiving.
Record type is open so that we specify the fields that we are interested that there can be more fields that we are not interested that that's why the record is open. So all good. And then what we have to do is instead of this JSON, we can simply return this books because we have created a map in record.
So now we can use that record instead of JSON. So now it's giving an error because the return type is a book which we are mentioning as a JSON here. So other important thing is like when we are returning something, we have to be exact about what we are returning. Basically be conservative a little bit when we are returning, we have to, we know exactly what we are returning. So we can define return types.
There we have to create close records. Sorry. We have to create close records here. You can notice this pipe notation. That means it's a close record. So I'm going to exactly return the interested fields only. So what are the interested fields? Basically, I am interested. It's this self-link and these three fields. So that's, that's only that I'm going to return. So everything is good. Let's rename this into book data. And so what we are going to return is book data array. So we have to create this book data array because the return, when we search for a title, it will return an array. We need to create an array here. So let me create a book data array as book data. There, I'm going to use another feature
in Ballerina that is query syntax. For the moment, let's rename this, change this to a text so that it won't compile, give a compile time error. Query syntax means we can easily use a usual SQL-like syntax to extract data. So there, what I'm going to use is from items. I'm going to iterate this array, items array and extract the data that I want for from items. Let's name is that item. In books, items, I'm going to select the required fields only. So what we need is title. Let's fill the exact values later.
Average rating. And info link. And self link. Those are the things that I need. I need the semicolon here. And now we can simply fill it using the real values item dot volume in for title. And item dot volume in for average rating. So here infolink, instead of infolink, let me use authors. There's another field called authors.
And let's use that. Let me quickly check from my original code. Yes, it's authors that I'm interested that. I mistakenly deleted another field, authors and took another field. So this is also authors. This is also authors. All good. So I'm going to copy this. I'm going to copy this. Okay. All good. Self link and other information. And yeah, I'm interested that item dot self link means item dot self link. And finally, authors means item dot volume in for authors. So everything seems good. Let's quickly run it. So now we are going to return this book data instead of JSON. That is the interested data set. So let's return book data from this resource function. So instead of this huge JSON, I should be able to return the
the required information or the interested information only. Let's clean the screen. And let's wait a bit to get it up and running. Okay, it's running. Let's do the same command as before. Sorry, I think I have mistakenly. Yes, let me quickly copy because I changed somewhere in between. So if I copy from here, let me quickly copy the full code so that it will be easy for me to demonstrate.
I think I changed a little bit about the return types and that caused some error. And I'm not handling errors explicitly here to the simplicity. This is the full code so that I can show you the exact details and I'm running out of time a little bit. So here, let me quickly run it while I'm explaining. So this is the same code. Everything is in order. And also, I call the other endpoint, that is the movie endpoint. There also, we need to create another HTTP client because this is another different endpoint. And also, it is returning different types.
So these different movie types also, I have defined them. I follow the same method. Basically, we can follow the same method, that same utility to convert a JSON to the record here as well. And then, it will create the required details. And also, the return types. I have to define the exact return types as closed records because that will be easy for the developers to generate open API descriptions. And also, they know exactly what are the field types. So it's running. And let me quickly execute the command.
It will take a bit of time because it is calling three endpoints, three times, three network calls. Now you can see the output. Actually, I skipped part of it because it's similar. Like we are dealing with network endpoints and creating records and processing the output. Only important thing is like this query syntax I showed in my code. Where we are selecting the interested information. And also, we can put some filters here to filter out unnecessary values. Here, I am filtering out if the average rating is nil, I am filtering it out. So finally, after fetching from all the endpoints, this is the first movie endpoint call. And this is the second endpoint call based on the ID. I am extracting the ID here and calling that
as well. So everything seems good. And that's why we are returning a combined record. That is book data as well as the movie data. So book data is an array. So in the response, you can see this is the book data array. And this is the full full title and year and link for the movie. So actually, I skipped part of it just for the simplicity. And likewise, we can process any different types of data, JSON, XML, and everything.
So it gives the flexibility to convert and transform maybe our process data in different formats. And that's the differential factor here. So then let me quickly go through the diagram here. So this is the generated diagram, as I mentioned before. So diagram is auto generated. Let's expand it a little bit. It has a get from search function, I expanded it. Let me close this. So you can see the diagram here.
So the diagram is exactly similar to what we saw in the demo, like what we have described. Basically, it's calling book endpoint, getting some value and processing it, you can see the processing logic also. And it has a movie endpoint, two calls to the movie endpoint. So everything is visible. This is not something like something. Let's say we are adding some if condition here. Diagram editing is supported.
Let's put some value like true. So you can see the code is generated as well. And then let's say, let's simply do another dummy call here. You can see how the diagram is generated. So we added another call to the source code. Actually, we don't need it for the use case, but I just added it for visualization purpose. So the diagram is auto updated. So we have one to one mapping between the source code and diagram. That is the other important feature. So the final part I'm coming towards the end of my demo is about running or working in the cloud.
So there what you have to do is you have to build this using the cloud parameters. So usually what we have to do is we have to add CloudTML here with all the properties and other parameters. But since I don't have any specific thing, I don't use it. And what I have to do is minus minus cloud, let's say Kubernetes.
It will build quickly. And it will generate the required articles. In the target folder, we don't have anything at the moment. And let's see how it goes. It will take a bit of time. It is generating. There are four steps and it's completing. Okay, everything seems good. And it has generated the artifacts here. You can see the Docker file is auto generated with all the layers. And it has taken the port from the code.
And also in the Kubernetes artifacts, you can see the YAML files with all the descriptors. So that is something which is very easy for developers. And so that they can generate the cloud artifacts easily. So that is actually end of my demo, as well as my presentation about Ballerina. Let me quickly go through the final step of it, basically contributing Ballerina. Ballerina is an open source language. And anyone in the world are welcome to help Ballerina or use Ballerina by use or contribute it. So we have different communication channels, Slack, the Google group, Ballerina, the Google group, and also all the source code is free and open source in GitHub platform. So you can go and contribute. So that is about Ballerina. I hope you got some understanding about the new language as well as some fun with the
coding session. Thank you very much for joining.
Transcribed automatically; names checked against the speaker record. Select a time to jump there.
Article based on this talk
Why build a new programming language for cloud integration?
WSO2's Anupama Pathirage shows how Ballerina puts network calls, typed data and cloud deployment into the language itself.
In short
Anupama Pathirage, Director of Engineering at WSO2 and a developer of the Ballerina language, argues that cloud-era applications are so integration heavy that network handling belongs in the language itself, not in add-on libraries and hand-written deployment files. She walks through Ballerina's design choices, then live-codes a REST service that calls external APIs, shapes the returned data, draws its own sequence diagram and generates its own Docker and Kubernetes artifacts.
Key takeaways
Latest trends in integration and cloud native development
Open source development and its importance
The art of programming language development
Cloud work does not end at deployment
Pathirage opens with a familiar dilemma: ask a developer which programming language is best for a given scenario and there are thousands of possible answers. She then points to the IBM Cloud Native Development Report, which, as the speaker cited, says around 55% of new applications will go directly into the cloud, while most existing non-cloud applications will need to move there soon.
"So cloud development is not something that we can avoid." (1:19)
The classic cycle of requirements, design, implementation, testing, packaging and deployment gains a continuous loop in the cloud. Developers write Docker files and deployment descriptors, manage APIs and security for network-facing code, tune scaling and performance, observe usage and analytics, and sometimes redesign the application based on what they learn.
Why a new language at all
Existing languages are good at many things, Pathirage says, but modern applications interact with many endpoints at once, and that changes what developers need from a language.
"So we need better network abstractions and also better support for network data or the data representation." (4:33)
Her list of requirements is specific: a type system that is aware of the network, first-class support for protocols such as gRPC, WebSocket, HTTP and WebSub, strong concurrency support because network interactions are inherently concurrent, easy movement of code into the cloud, visual representations of complex logic, and a complete platform rather than a bare language. WSO2 started Ballerina in 2016 as a replacement for its Synapse-based applications, released a first version in 2019 and shipped the Swan Lake version in February 2022. Although WSO2 started and maintains it, the project is community driven.
"So anyone in the world can contribute and use it without any charge." (6:12)
The design choices behind Ballerina
The name comes from choreography: dancers each play a role and must stay in sync, just as network interactions must happen on time as planned. The language has objects but does not force them; developers can use functions instead. Its primary focus is plain, network-transmitted data. It is compiled, and it is flexibly typed, sitting between rigid static typing and loose dynamic typing.
"So we stay in the middle, depending on the different situations." (9:35)
Pathirage outlines the features that make this practical. Clients and services are language concepts, with resource methods for data-oriented access and remote methods for scenarios such as GraphQL. An anydata type serializes naturally to JSON and other formats, alongside records, tables, maps, arrays, XML and JSON. The language includes asynchronous calls, workers and strands for concurrency, plus syntax for transactions. Two implementations exist: jBallerina, written in Java on the JVM and production ready, and nBallerina, compiled with LLVM to native code and still in progress at the time. Around the core sits a standard library, a module repository, a documentation system, a testing framework and a VS Code plugin.
A live demo: searching books and movies
The demo builds a novel service that takes a book title, queries the Google Books API and a movies API, and returns a combined result. Pathirage creates a package with the bal command, opens it in VS Code, defines an HTTP listener and a search resource, and tests it with curl. When she adds an HTTP client, the editor flags that creating it can fail, which leads to one of Ballerina's core ideas.
"Instead of throwing exceptions like other common languages, we are returning errors." (22:44)
Errors are part of union types, type narrowing removes them once checked, and the check keyword passes them up so the HTTP listener can turn them into an HTTP 500 or relevant error. She then pastes the raw JSON response into a tool that generates record types, trims them to the fields she cares about, and explains the principle of being liberal in what you accept and exact in what you return.
"That is the concept of open record in ballerina. Basically being a bit liberal about what we are receiving." (27:16)
Closed records for responses make it easier to generate OpenAPI descriptions, and an SQL-like query syntax extracts and filters data, for example dropping books with no average rating.
From code to diagram to cloud
The service's logic appears as an auto-generated sequence diagram showing each endpoint call. Pathirage adds an if condition and an extra call in the diagram and the source code updates to match.
"That means if you edit the code, diagram will be auto-generated. And if you edit the diagram, code will be generated." (14:12)
Finally she builds with a cloud option set to Kubernetes. Ballerina generates a Dockerfile, taking the port from the code, and the Kubernetes YAML descriptors.
"So it's just a matter of giving this command and putting some configurations if needed." (12:54)
She closes by inviting developers to join the community through Slack, the Google group and the open source code on GitHub.
Watch the talk
"Ballerina: Cloud-Native Middleware as a Programming Language" by Anupama Pathirage, about 40 minutes: https://www.womentech.net/video/ballerina-cloud-native-middleware-programming-language-anupama-pathirage
About the speaker
Anupama Pathirage is Director of Engineering and Engineering Manager of the open source Ballerina project at WSO2 (PVT) Limited, where she has contributed to the language's compiler, runtime, transactions, tables, database clients and data handling. She has also led customer engagements for integration and data services projects, and holds a Master's degree in Software Architecture and a first-class honors Bachelor's degree from the Department of Computer Science and Engineering of the University of Moratuwa, Sri Lanka.
Questions this talk answers
Why did WSO2 build a new programming language?
Is Ballerina a JVM language?
How does Ballerina handle errors from network calls?
How does Ballerina help move code into the cloud?
How can developers get involved with Ballerina?
Drafted with AI from the talk transcript. Editor review pending.
Resources mentioned
Ballerina VS Code plugin
Ballerina Central
Ballerina Slack
Ballerina Google group
Ballerina on GitHub
Cite this talk
Anupama Pathirage. "Ballerina: Cloud-Native Middleware as a Programming Language." WomenTech Network, 2022. https://www.womentech.net/video/ballerina-cloud-native-middleware-programming-language-anupama-pathirage