Hands-On Microservices with Django - Tieme Woldman - E-Book

Hands-On Microservices with Django E-Book

Tieme Woldman

0,0
25,19 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

This book is for Django developers looking to create optimized and scalable web applications using microservices. With it, you’ll learn the principles of microservices and message/task queues and build your first microservices with Django RESTful APIs (DFR) and RabbitMQ. You’ll also master the fundamentals, dockerize your microservices, and optimize and secure them for production environments. By the end, you'll have the skills to design and develop production-ready Django microservices applications with DFR, Celery/RabbitMQ, Redis, and Django's cache framework.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 299

Veröffentlichungsjahr: 2024

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Hands-On Microservices with Django

Build cloud-native and reactive applications with Python using Django 5

Tieme Woldman

Hands-On Microservices with Django

Copyright © 2024 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Bhavya Rao

Book Project Manager: Shagun Saini

Senior Editor: Nathanya Dias

Technical Editor: Simran Ali

Copy Editor: Safis Editing

Indexer: Pratik Shirodkar

Production Designer: Prashant Ghare

DevRel Marketing Coordinators: Anamika Singh and Nivedita Pandey

First published: April 2024

Production reference: 1010424

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK.

ISBN 978-1-83546-852-4

www.packtpub.com

Books are written by teams, not just by the author whose name is on the front cover. So, a big compliment to all the people who helped me to create this book.

– Tieme Woldman

Contributors

About the author

Tieme Woldman works as a freelance Python developer and technical writer. As a Python developer, he builds web and data engineering applications with Django and Python data transformation packages such as pandas. As a technical writer, he has written software and user documentation for software companies such as Instruqt, Noldus Information Technology, and Rulecube.

Tieme lives in the Netherlands, has a bachelor’s degree in computer science, and holds several (technical) writing certifications.

About the reviewers

Uwem Akpabot has 13 years of progressive professional experience as a full stack software developer. He earned a master’s degree in software engineering from the University of Greenwich, United Kingdom, in 2013. He has held managerial/supervisory positions where he led teams in the successful delivery of projects. His expertise includes Python programming, Java, PHP, JavaScript, and problem-solving with data structures and algorithms. As a developer, he is eager to create reliable solutions that are easy to use or modify and can perform flawlessly. As a gifted instructor, he creates excellent courses that help others learn programming.

Afeez Lawal is an experienced Django backend engineer with a proven track record of designing and developing innovative software solutions. With a keen eye for detail and a passion for problem-solving, Afeez has successfully delivered a range of projects, demonstrating expertise in backend development, particularly using the Django framework.

Table of Contents

Preface

Part 1: Introducing Microservices and Getting Started

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

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

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

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

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

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

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

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

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

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

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

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

Part 1:Introducing Microservices and Getting Started

In this part, you’ll learn what microservices are and how you design them. Furthermore, you’ll learn about the Django microservices architecture and its components. Finally, you’ll master setting up your development and runtime environment for building and deploying Django microservices applications.

This part contains the following chapters:

Chapter 1, What Is a Microservice?Chapter 2, Introducing the Django Microservices ArchitectureChapter 3, Setting Up the Development and Runtime Environment