2021 Issue 1

Issue #1 - March 3, 2021

Services and Network Communication in Swan Lake

Ballerina is built to inherently make network communication easier, by making networking concepts like client objects, services, resource functions, and listeners a part of the syntax. This allows you to use the language-provided constructs to write network programs that just work. The new Swan Lake release introduces many improvements around the services abstraction in the language, and in protocol implementations. Let’s look at some of these!

A Ballerina service’s structure and its semantics are defined by the type of the listener. An example of this is shown in the definition of an HTTP service below.

HTTP service

Read this DZone article on HTTP Deep-Dive with Ballerina: Services to learn the basics of creating an HTTP service and how Ballerina provides a convenient abstraction for defining complex operations.

Ballerina also has a first-class construct to create an HTTP client object and provide the necessary host and configuration information. Read this DZone article on HTTP Deep-Dive With Ballerina: Client Communication where we explore Ballerina’s feature-complete functionality that allows you to implement any HTTP client scenario.

WebSocket is another communication protocol, which is used for efficient full-duplex communication between web browsers and servers over TCP. It fulfills the requirements of dynamic websites while fixing shortcomings of techniques like HTTP. Ballerina’s easy-to-use networking abstractions can also be used to create WebSocket clients and services. Read this Hackernoon article on An Introduction to WebSockets with Ballerina to learn more.

GraphQL has become a prominent technology when implementing data APIs. It provides an efficient and intuitive approach for querying data over the network. It solves potential problems such as data over-fetching and network latency that can arise in a services-based solution. Ballerina provides built-in support for quickly and easily implementing GraphQL services, allowing users to concentrate on the business logic. Learn more in this DZone article on GraphQL Made Easy With Ballerina.

For network operations to function optimally, it’s critical to support non-blocking I/O-based communication. Ballerina has a unique concurrency model, based on a lightweight thread model, which supports user-space scheduling for concurrent executions. This makes it possible to implement an efficient non-blocking I/O functionality right from the language primitives. Dive into more details with this DZone article on Ballerina Concurrency Model and Non-Blocking I/O.

What’s New in Ballerina?

The second Swan Lake Alpha release happened on Saturday, February 20! Check out the release note for the full feature list.

Here is a summary of the key features in Ballerina Swan Lake Alpha 1 and 2:

  • Support for configurability with configurable variables
  • Support for the list, mapping, and error binding patterns in the match statement
  • Improved user-defined error creation syntax with improved error handling semantics to prevent developers from masking errors
  • The ballerina command has been renamed to bal
  • Introducing bal shell command-line tool: The Ballerina REPL that interactively runs Ballerina code snippets and immediately evaluates their results
  • Improvements to developer tools such as the VSCode plugin, Debugger, Test Framework, Bindgen Tool, and Documentation
  • Improvements to the HTTP, WebSocket, gRPC, security, GraphQL, Kafka, NATS, NATS Streaming, RabbitMQ, Time, Runtime, Email, and WebSub standard library modules
  • Introduction of the new Random, RegEx, TCP, UDP, and WebSubHub standard library modules

Download the Alpha 2 version, try it out and let us know your feedback via our Slack channel.

Ballerina Community Call

If you’d like to have a discussion with our engineering team on Ballerina concepts and how you can use it in your projects, join our next community call. In our previous call, we discussed in detail about Ballerina Swan Lake’s services and network communication. Sign up here to get notified.

We hope you found this information useful. We’ll catch you again soon!

Privacy Policy  |   Terms of Service

Want to get hand-picked content and the latest news on Ballerina delivered directly to your inbox? Then subscribe to our monthly newsletter today!