Kotlin has been the buzzword among developers ever since the release of new features in Kotlin 1.1. With Google's announcement of introducing first class support for Kotlin in their Android ecosystem, it's high time that Kotlin is realized as a mainstream language. Microservices aids in designing sc
Hands-On Microservices with Django: Build cloud-native and reactive applications with Python using Django 5
β Scribed by Tieme Woldman
- Publisher
- Packt Publishing
- Year
- 2024
- Tongue
- English
- Leaves
- 278
- Edition
- 1
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Unlock the potential of microservices architecture and master the art of building scalable and resilient web applications using Django
Key Features
Deliver, optimize, and secure high-performing microservices in Django
Apply community-standard components for microservices like DRF (RESTful APIs), Celery, RabbitMQ, Redis, and Django's Cache Framework
Transform existing monolithic applications into microservices
Purchase of the print or Kindle book includes a free PDF eBook
Book Description
Are you a Django developer looking to leverage microservices to create optimized and scalable web applications? If yes, then this book is for you. With microservices, you can split an application into self-contained services, each with a specific scope running asynchronously while collectively executing processes. Written by an experienced Python developer, Hands-On Microservices with Django teaches you how to develop and deploy microservices using Django and accompanying components such as Celery and Redis.
You'll start by learning the principles of microservices and message/task queues and how to design them effectively. Next, you'll focus on building your first microservices with Django RESTful APIs (DFR) and RabbitMQ, mastering the fundamentals along the way. As you progress, you'll get to grips with dockerizing your microservices. Later, you'll discover how to optimize and secure them for production environments.
By the end of this book, you'll have the skills you need to design and develop production-ready Django microservices applications with DFR, Celery/RabbitMQ, Redis, and Django's cache framework.
What you will learn
Understand the architecture of microservices and how Django implements it
Build microservices that leverage community-standard components such as Celery, RabbitMQ, and Redis
Test microservices and deploy them with Docker
Enhance the security of your microservices for production readiness
Boost microservice performance through caching
Implement best practices to design and deploy high-performing microservices
Who this book is for
This microservices and Django book is for Django developers who want to take the next step in back-end application development by adopting cloud-native microservices. Backend developers with working knowledge of Flask or other Python programming web frameworks will also benefit from this book. Basic knowledge of developing web APIs will help you get started with quickly building microservices on your own.
β¦ Table of Contents
Cover
Title Page
Copyright and Credits
Dedication
Contributors
Table of Contents
Preface
Part 1: Introducing Microservices and Getting Started
Chapter 1: What Is a Microservice?
Comparing monolithic web applications and microservices
A monolithic version of a Discount Claim app
A microservices version of the Discount Claim app
Characteristics of microservices
Exploring the microservices architecture and its components
An analogy to deepen our understanding of microservices
Listing the benefits of microservices
The drawbacks of microservices
Distinguishing types of microservice
Cloud-native microservices
Reactive microservices
Designing microservices
Analyzing the user story
Split the user story into use cases
Summary
Chapter 2: Introducing the Django Microservices Architecture
Technical requirements
Exploring Djangoβs native components for microservices web applications
DRF
Djangoβs Cache Framework
Traversing the external components for Django microservices web applications
Task and message queue brokers
Container software
The complete Django microservices architecture
Creating a sample microservice
Implementation 1: Offloading a task with a RabbitMQ microservice
Implementation 2: Offloading a task with a Celery microservice
Summary
Chapter 3: Setting Up the Development and Runtime Environment
Technical requirements
Setting up the development environment
Extra setup for Windows developers
Installing the required Python packages
Setting up the runtime environment
Installing Docker Desktop
Installing RabbitMQ as a Docker container
Installing Redis as a Docker container
Signing up for MongoDB and working from VS Code
Analyzing the sample microservices application
Matching an address
The appβs requirements as user stories
Splitting the requirements into use cases
Phasing the development of the sample application
Summary
Part 2: Building the Microservices Foundation
Chapter 4: Cloud-native Data Processing with MongoDB
Technical requirements
Introducing MongoDB and cloud-native databases
What are cloud-native databases?
MongoDB is a NoSQL database
Setting up MongoDB
Optional: creating a paid cluster for production databases
Creating a database user
Setting up our MongoDB cluster for Django
Creating a Database
Creating documents inside a collection
Updating documents
Deleting documents and collections
Mapping CRUD operations to HTTP methods
CRUD operations on MongoDB with Django ORM
CRUD operations on MongoDB with pymongo
Cleaning up
Summary
Chapter 5: Creating RESTful APIs for Microservices
Technical requirements
Introducing RESTful APIs
Benefits of RESTful APIs
The RESTful API architecture
Building RESTful APIs with DRF
Setting up DRF
Creating a model and a serializer
Creating a view and the URL endpoints
Browsing a DRF RESTful API
Error handling
Handling wrong-formatted requests
Handling validation errors
Summary
Chapter 6: Orchestrating Microservices with Celery and RabbitMQ
Technical requirements
Introducing task queues
Implementing the work queue scenario
Implementing the Publish-Subscribe scenario
Implementing the Request-Response scenario
Exploring Celery and RabbitMQ
Celery
RabbitMQ
Creating and running asynchronous tasks
Creating and running a Celery-based task
Creating and running a RabbitMQ-based task
Monitoring tasks and task queues
Monitoring Celery tasks with Flower
Monitoring RabbitMQ tasks
Summary
Chapter 7: Testing Microservices
Technical requirements
Introducing testing microservices
Unit testing microservices
Creating and running happy path tests
Creating and running boundary tests
End-to-end testing microservices
Automated testing with Selenium
Summary
Chapter 8: Deploying Microservices with Docker
Technical requirements
Introducing Docker
Benefits of Docker (containers)
Containerizing microservices
Applying multi-container deployment with Docker Compose
Deploying a Django microservices application
Showing a list of the images we created
Showing a list of created and running containers
Inspecting the console output of a container
Stopping a container
Starting a container
Removing a container
Removing an image
Deploying a new microservices version
Scaling microservices
Vertical and horizontal scaling
Docker Swarm
Kubernetes
Summary
Part 3: Taking Microservices to the Production Level
Chapter 9: Securing Microservices
Technical requirements
Introducing microservices security
North-south security for microservices
East-west security for microservices
Token-based security with JWT
User-based security with OAuth 2.0
Controlling access to microservices
Securing data communication between microservices
Summary
Chapter 10: Improving Microservices Performance with Caching
Technical requirements
Introducing caching
Applying Djangoβs cache framework
Caching a web page
Caching page data
Using Redis for caching
Redis as a backend cache for Djangoβs cache framework
Redis as a standalone cache
Summary
Chapter 11: Best Practices for Microservices
Technical requirements
Organizing code
Apply the singe task principle
Separate responsibilities
Standardize the communication protocols
Containerize microservices
Apply version control
Document the code
Conduct code reviews
Documenting microservices
Provide code comments
Create a README file for the microservices application
Document RESTful APIs
Logging and monitoring
Apply integrated logging
Implement log levels
Log context information
Alert anomalies
Error handling
Catch and log errors
Other error handling options
Versioning microservices
Apply semantic versioning
Utilize RESTful API versioning
Summary
Further reading
Chapter 12: Transforming a Monolithic Web Application into a Microservices Version
Introducing the transformation approach
Implementing the approach step by step
Determining requirements
Decomposing the monolith
Designing the microservices
Selecting the technology
Creating the data foundation
Developing the microservices
Testing and deploying
Summary
Index
Other Books You May Enjoy
π SIMILAR VOLUMES
A step-by-step guide to building web applications with Python and Django 3.0. Create, test, and deploy 5 progressively more complex websites including a Message Board app, a Blog app with user accounts, and a robust Newspaper app with reader comments and a complete user registration flow. Along the
<p><b>Discover how project Reactor enhances the reactive programming paradigm and allows you to build scalable asynchronous applications</b></p> Key Features <li>Use reactive APIs, Flux, and Mono to implement reactive extensions </li> <li>Create concurrent applications without the complexity of Java