Applications built for the cloud from the beginning use its strengths better than old applications that were only moved to it.
Cloud-Native Architecture
Cloud-native applications are designed to run in the cloud, and use microservices, containers, dynamic orchestration, and automation. A monolithic application is one large unit that is hard to scale and change as a whole. In a microservices design, an application is split into small, independent services, each doing one job, with its own data, talking to others through APIs. Each service can be developed, deployed and scaled alone, and may use its own language. The difficulties are more complexity, network calls, and the need to watch many services. Supporting patterns are the API gateway, a single entry point, service discovery, message queues for loose coupling, and a service mesh such as Istio for the traffic between services. The twelve-factor app is a set of good practices, such as keeping settings in the environment and making processes stateless.
Definition: Microservices. An architectural style that builds an application as a set of small, independent services, each doing one business function and communicating with the others through lightweight APIs.
Serverless in Cloud-Native Design
Serverless functions fit well in a cloud-native design. They handle event-driven tasks, such as image processing on upload, and glue the services together. An application may mix containers for steady services and functions for occasional events.
DevOps and CI/CD
DevOps joins development and operations to deliver software quickly and reliably. Continuous integration (CI) merges and tests code changes often. Continuous delivery or deployment (CD) automatically releases tested code to production. Tools are Git, Jenkins, GitHub Actions and GitLab CI. Infrastructure as Code builds the environment in the same way each time. Release patterns such as blue-green and canary deployments reduce the risk of a new version.
Deploying a Cloud Application
The steps for a simple web application are as follows. Write and test the code locally. Package it in a container. Push the image to a registry. Create the infrastructure, such as a network, a database and a cluster, with code. Deploy the container to a service such as a managed Kubernetes cluster or a PaaS. Configure a load balancer, a domain name and TLS. Set up monitoring, logging and alerts, and auto-scaling. Secure it with IAM, secrets and firewalls. Update it through a CI/CD pipeline. In the labs of this course, students deploy a small application to a cloud platform in this way.
Table 4.4: Monolith and microservices
| Feature | Monolith | Microservices |
|---|---|---|
| Structure | One unit | Many small services |
| Scaling | Whole application | Each service alone |
| Deployment | All together | Independent |
| Complexity | Simpler at first | Higher, more to manage |
Example 4.4: Scaling a microservice
Problem: An online shop has services for catalogue, cart and payment. On a sale day the catalogue gets 10 times the load but the others only twice. In a monolith, how much must be scaled? In microservices?
Solution:
- A monolith must be scaled as a whole for the highest load, 10 times, so cart and payment code also get 10 copies.
- With microservices, scale catalogue 10 times, and cart and payment 2 times.
Result: Microservices save resources by scaling each part by its own need.
load = {"catalogue": 10, "cart": 2, "payment": 2}
mono = max(load.values()) * len(load)
micro = sum(load.values())
print(mono, micro)
Output
30 14
Common mistakes
- Splitting an application into microservices that are too small, which makes it hard to manage.
- Sharing one database among all microservices, which couples them again.
- Deploying by hand, which causes errors and slow releases.
Key takeaways
- Cloud-native applications use microservices, containers and automation.
- Microservices scale and deploy independently, but add complexity.
- CI/CD automates the testing and release of code.
- Deployment steps: package, push, provision, deploy, secure, monitor.
Practice questions
- What are microservices?
- What is CI/CD?
- Why use containers for deployment?
Answers to the practice questions
- Small independent services, each doing one function and communicating by APIs, which together form an application.
- Continuous integration and delivery, which automatically builds, tests and releases code changes.
- They package the application with its dependencies so that it runs the same everywhere.
Sources
- Official BCA syllabus Cloud Computing, course code 25BCA405DS03, Unit IV
