0%

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