Cloud Native Applications with Ballerina

Book description

Learn how to build scalable cloud native applications with the new-generation Ballerina language using expert tips and best practices

Key Features

  • Work with code samples based on the Ballerina Swan Lake Beta1 version
  • Explore the in-built networking protocol support in Ballerina to develop secure distributed apps
  • Build a Ballerina app with an automated CI/CD pipeline with observability to simplify maintenance and deployment

Book Description

The Ballerina programming language was created by WSO2 for the modern needs of developers where cloud native development techniques have become ubiquitous. Ballerina simplifies how programmers develop and deploy cloud native distributed apps and microservices.

Cloud Native Applications with Ballerina will guide you through Ballerina essentials, including variables, types, functions, flow control, security, and more. You'll explore networking as an in-built feature in Ballerina, which makes it a first-class language for distributed computing. With this app development book, you'll learn about different networking protocols as well as different architectural patterns that you can use to implement services on the cloud. As you advance, you'll explore multiple design patterns used in microservice architecture and use serverless in Amazon Web Services (AWS) and Microsoft Azure platforms. You will also get to grips with Docker, Kubernetes, and serverless platforms to simplify maintenance and the deployment process. Later, you'll focus on the Ballerina testing framework along with deployment tools and monitoring tools to build fully automated observable cloud applications.

By the end of this book, you will have learned how to apply the Ballerina language for building scalable, resilient, secured, and easy-to-maintain cloud native Ballerina projects and applications.

What you will learn

  • Understand the concepts and models in cloud native architecture
  • Get to grips with the high-level concepts of building applications with the Ballerina language
  • Use cloud native architectural design patterns to develop cloud native Ballerina applications
  • Discover how to automate, maintain, and observe cloud native Ballerina applications
  • Use a container to deploy and maintain a Ballerina application with Docker and Kubernetes
  • Explore serverless architecture and use Microsoft Azure and the AWS platform to build serverless applications

Who this book is for

This Ballerina Swan Lake book is for cloud developers, integration developers, and microservices developers who are facing challenges with legacy tooling and are looking for the latest tools and technologies to solve them. Beginner-level programming knowledge is required before getting started with this Ballerina book.

Table of contents

  1. Cloud Native Applications with Ballerina
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Share Your Thoughts
  6. Section 1: The Basics
  7. Chapter 1: Introduction to Cloud Native
    1. Evolution from the monolithic to the microservice architecture
      1. The N-tier architecture in monolithic applications
      2. Monolithic application architecture
      3. The ESB simplifies SOA
    2. The emergence of microservices
    3. Understanding what cloud native architecture is
      1. Cloud computing
    4. Serverless architecture
      1. Definition of cloud native
      2. Why should you select a cloud native architecture?
    5. Challenges of cloud native architecture
      1. Security and privacy
      2. The complexity of the system
      3. Cloud lock-in
    6. Deploying cloud native applications
      1. Design is complex and hard to debug
      2. Testing cloud native applications
      3. Placing Ballerina on cloud native architecture
    7. Building cloud native applications
      1. The twelve-factor app
      2. Code base
      3. Dependencies
      4. Config
      5. Backing services
      6. Dev/prod parity
      7. Admin processes
      8. API-first design
      9. The 4+1 view model
      10. Building an order management system
      11. Breaking down services
    8. Impact on organizations when moving to cloud native
      1. Challenges of moving to a cloud native architecture
      2. Outdated technologies
      3. Building cloud native delivery pipelines
      4. Interservice communication and data persistence
      5. Conway's law
      6. Netflix's story of moving to cloud native architecture
    9. Summary
    10. Questions
    11. Further reading
    12. Answers
  8. Chapter 2: Getting Started with Ballerina
    1. Technical requirements
    2. Introduction to the Ballerina language
      1. A glimpse of Ballerina
      2. The Ballerina compiler
      3. The Ballerina threading model
    3. Setting up a Ballerina environment
      1. Downloading and installing Ballerina
      2. Setting up VS Code
      3. Using VS Code to develop a Ballerina application
      4. Writing a simple "hello world" program
      5. Building a Ballerina project
    4. Understanding the Ballerina type system
      1. Simple types
      2. Structured types
      3. Sequence types
      4. Behavioral types
      5. Other types
      6. Working with types
    5. Using types to build applications with Ballerina
      1. Controlling program flow
      2. Ballerina functions
      3. Treating functions as variables
      4. The Ballerina main function
      5. Working with Ballerina classes
      6. Ballerina objects
      7. Error handling
      8. Using custom errors
    6. Summary
    7. Questions
    8. Answers
  9. Section 2: Building Microservices with Ballerina
  10. Chapter 3: Building Cloud Native Applications with Ballerina
    1. Technical requirements
    2. Ballerina cloud native syntaxes and features
      1. The role of Ballerina in cloud native architecture
    3. Building a Ballerina HTTP service
      1. Passing data to HTTP resources
      2. Using query parameters on an HTTP server
      3. Passing structured data to HTTP services
      4. Invoking remote HTTP services
      5. Ballerina JSON support
      6. Working with XML format in the Ballerina language
      7. Ballerina remote methods
    4. Containerizing applications with Ballerina
      1. Introduction to containers
      2. Containers versus VMs
      3. Containerizing applications with Docker
      4. Building a Docker image with Ballerina
      5. Using Ballerina's development Docker image
    5. Container orchestration with Kubernetes
      1. Introduction to Kubernetes
      2. Generating Kubernetes artifacts with Ballerina
      3. Utilizing Kubernetes resources
      4. Using config maps in the Kubernetes cluster
      5. Configuring a Kubernetes health check for Ballerina services
      6. Using Kustomize to modify Ballerina Kubernetes configurations
    6. Summary
    7. Questions
    8. Further reading
    9. Answers
  11. Chapter 4: Inter-Process Communication and Messaging
    1. Technical requirements
    2. Communication between services in a microservice architecture
      1. Communication over services in the Kubernetes cluster
      2. Using environment variables for service discovery
      3. Using the Kubernetes DNS resolver for service discovery
      4. Using a service mesh to simplify inter-service communication
      5. Service discovery in a service mesh by using Consul
      6. Using resiliency patterns in Ballerina
      7. Ballerina client-side load balancing
    3. Synchronous communication
      1. Handling HTML form data
      2. Building a Ballerina backend with GraphQL
      3. Using the OpenAPI Specification with Ballerina
      4. Building a chat application with WebSocket
      5. Building Ballerina services with the gRPC protocol
    4. Asynchronous communication
      1. Asynchronous communication over microservices
      2. Building the publisher and subscriber pattern with Apache Kafka
      3. Connecting Ballerina with Kafka
      4. Connecting Ballerina with RabbitMQ
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  12. Chapter 5: Accessing Data in Microservice Architecture
    1. Technical requirements
    2. Accessing data with Ballerina
      1. Connecting the Ballerina application with MySQL
      2. Querying from MySQL
      3. Using parameterized queries
      4. Using batch execution
      5. MySQL data types and Ballerina data types
      6. Connecting databases with JDBC drivers
      7. Connecting Ballerina application with DaaS platforms
    3. Managing transactions in Ballerina
      1. Building an order management system
      2. Initializing the MySQL database for the order management system
      3. Building an order management system with Ballerina
      4. Understanding ACID properties
      5. Ballerina transaction management
      6. The database-per-service design pattern
    4. The role of Domain-Driven Design in cloud native architecture
      1. Creating aggregates with Ballerina
      2. Distributed transactions with saga
      3. Building a saga orchestrator with Ballerina
    5. Using event sourcing and CQRS in a distributed system
      1. Using events to communicate among services
      2. Developing with event sourcing
      3. Creating aggregates with event sourcing
      4. Creating snapshots
      5. Querying in microservice architecture
    6. Summary
    7. Questions
    8. Further reading
    9. Answers
  13. Section 3: Moving on with Cloud Native
  14. Chapter 6: Moving on to Serverless Architecture
    1. Technical requirements
    2. Introducing serverless architecture
    3. Developing Ballerina applications with Azure Functions
      1. Introducing Azure cloud features
      2. Building serverless applications with the Azure cloud
      3. Building Ballerina applications with Azure Queue
    4. Developing Ballerina applications with AWS Lambda functions
      1. Understanding AWS Cloud services
      2. Configuring the AWS CLI and AWS Console
      3. Creating your first Ballerina AWS Lambda function
      4. Adding triggers to invoke a Lambda function
      5. Using AWS Step Functions with an AWS Lambda function
      6. Building the Lambda function with Ballerina
      7. Creating Step functions in the AWS Console
      8. Creating an API gateway to invoke Step functions
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  15. Chapter 7: Securing the Ballerina Cloud Platform
    1. Technical requirements
    2. Managing certificates in Ballerina applications
      1. Securing the Ballerina service with HTTPS
      2. Calling an HTTPS endpoint with Ballerina
      3. Securing Ballerina interservice communication with mutual SSL
    3. Authenticating and authorizing with LDAP user stores
      1. Authenticating and authorizing users with the LDAP server
      2. Setting up Apache Directory Studio
      3. Authenticating and authorizing Ballerina services with LDAP
    4. Token-based authorization with Ballerina
      1. Securing Ballerina services with a JSON Web Token
      2. Generating and validating a JWT with Ballerina
      3. Generating JWT with WSO2 Identity Server
      4. Authorizing Ballerina services with JWT
      5. Authorizing Ballerina services with WSO2 IS-generated JWT claims
      6. Building a Ballerina service with JWT authorization
      7. OAuth2 authentication and authorization with WSO2 IS
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
  16. Chapter 8: Monitoring Cloud Native Applications
    1. Technical requirements
    2. Introduction to observability and monitoring
      1. Observability versus monitoring
    3. Ballerina logging
      1. Printing logs with Ballerina
      2. Using Logstash to collect logs
      3. Using Logstash with Filebeat in container environments
      4. Using Elasticsearch to collect logs
      5. Using Kibana to analyze Ballerina logs
    4. Tracing with Ballerina
      1. Understanding the OpenTelemetry standard
      2. Using Jaeger as a tracing platform
      3. Monitoring the Ballerina application with Jaeger
      4. Creating custom spans with the Ballerina language
    5. Collecting and visualizing metrics with Ballerina
      1. Exposing metrics from Ballerina
      2. Collecting metrics with Prometheus
      3. Visualizing metrics with Grafana
      4. Creating custom metrics with Ballerina
    6. Summary
    7. Questions
    8. Answers
    9. Further reading
  17. Chapter 9: Integrating Ballerina Cloud Native Applications
    1. Technical requirements
    2. Fronting Ballerina services with an API gateway
      1. Building an API gateway with Ballerina
      2. Setting up and using WSO2 API Microgateway
      3. Using interceptors in Microgateway with Ballerina
    3. Building Ballerina integration flows with Choreo
      1. Introduction to Choreo low-code development
      2. Building HTTP services with Choreo
      3. Integrating services with Choreo
    4. Summary
    5. Questions
    6. Answers
  18. Chapter 10: Building a CI/CD Pipeline for Ballerina Applications
    1. Technical requirements
    2. Testing Ballerina applications
      1. Testing cloud native applications
      2. Writing a simple test in the Ballerina language
      3. Writing test functions with the Ballerina test framework
      4. Ballerina test reports
      5. Understanding Ballerina's testing life cycle
      6. Grouping Ballerina tests
      7. Mocking functions with Ballerina
    3. Automating a cloud native application's delivery process
      1. CI/CD pipeline in a cloud native application
      2. Using GitHub Actions with Ballerina
      3. Setting up GitHub Actions
    4. Building and deploying applications with Ballerina Central
      1. Introduction to Ballerina Central
      2. Building and publishing packages in Ballerina Central
      3. Publishing packages to Ballerina Central with GitHub Actions
      4. Using Ballerina Central packages
    5. Summary
    6. Questions
    7. Further reading
    8. Answers
    9. Why subscribe?
  19. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Cloud Native Applications with Ballerina
  • Author(s): Dhanushka Madushan
  • Release date: October 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800200630