Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Microservices with Django

You're reading from  Hands-On Microservices with Django

Product type Book
Published in May 2024
Publisher Packt
ISBN-13 9781835468524
Pages 278 pages
Edition 1st Edition
Languages
Author (1):
Tieme Woldman Tieme Woldman
Profile icon Tieme Woldman

Table of Contents (18) Chapters

Preface 1. Part 1:Introducing Microservices and Getting Started
2. Chapter 1: What Is a Microservice? 3. Chapter 2: Introducing the Django Microservices Architecture 4. Chapter 3: Setting Up the Development and Runtime Environment 5. Part 2:Building the Microservices Foundation
6. Chapter 4: Cloud-native Data Processing with MongoDB 7. Chapter 5: Creating RESTful APIs for Microservices 8. Chapter 6: Orchestrating Microservices with Celery and RabbitMQ 9. Chapter 7: Testing Microservices 10. Chapter 8: Deploying Microservices with Docker 11. Part 3:Taking Microservices to the Production Level
12. Chapter 9: Securing Microservices 13. Chapter 10: Improving Microservices Performance with Caching 14. Chapter 11: Best Practices for Microservices 15. Chapter 12: Transforming a Monolithic Web Application into a Microservices Version 16. Index 17. Other Books You May Enjoy

Preface

Hello, fellow Django developers and others interested in enhancing web applications with microservices. Microservices are playing an important role in today’s web applications. In 2020 alone, market researchers from Gartner saw a 42 percent increase in mentions of microservices architecture on social media. So, microservices are hot, raising questions regarding topics such as what they are and how we can apply them.

Fortunately, there is now enough experience building microservices to answer these questions from a real-world perspective. To give you a first idea, a microservice is a single-task piece of software that is part of a larger application and can be used by different applications.

As a result, microservices run asynchronously while collectively completing a process. As such, microservices are the opposite of monolithic applications, which perform all tasks sequentially from a single program, whereby one task can freeze the user experience because it takes seconds to complete.

This created the need for asynchronous processing with microservices as they let us split applications into task-driven components that run independently. So, the application proceeds without delay, which improves the user experience.

To develop and implement microservices, we need these main parts:

  • A producer, which is a program that offloads a task to a microservice
  • A task queue manager that passes the tasks to the microservices
  • A microservice, which is a program that listens to a queue and executes when a task arrives

There are many ways to implement these parts. Producers can be Django apps or other applications, such as React and Vue components. For the task queue manager, we have a choice of systems, such as Redis and RabbitMQ. And we can develop microservices in Python or another programming language, such as Node.js.

This book focuses on developing Django microservices and, therefore, covers these choices for the main microservices parts:

  • Django apps as producers.
  • Celery and Redis as task queue managers, as these are most common for Django. But the book also covers RabbitMQ, as this gives more profound insight into task queuing.
  • Python as the programming language for developing microservices.

The format of this book is hands-on, meaning it provides you with the necessary information about concepts and then provides extensive practical steps, examples, and explanations to build Django microservices yourself.

Who this book is for

This book is for Django developers who want to take the next step in backend application development by creating advanced applications with cloud-native microservices. Backend developers with working knowledge of Flask or other Python web frameworks would also benefit.

What this book covers

Chapter 1, What Is a Microservice?, provides an overview of the microservices architecture, its components, and its benefits. It also covers an approach to designing microservices.

Chapter 2, Introducing the Django Microservices Architecture, provides insight into the Django microservices architecture and walks through creating an example microservice to see what it takes to build microservices.

Chapter 3, Setting Up the Development and Runtime Environment, provides an overview of the software, systems, and packages needed to build and run microservices. It also covers the steps to install and configure the required parts.

Chapter 4, Cloud-Native Data Processing with MongoDB, lays a data foundation for a microservices application with the cloud version of the popular NoSQL database, MongoDB. This includes mapping CRUD operations to HTTP methods.

Chapter 5, Creating RESTful APIs for Microservices, extends the data layer for Django microservices by explaining how to create a RESTful API for serving microservice data operations toward MongoDB.

Chapter 6, Orchestrating Microservices with Celery and RabbitMQ, provides the basics of the task queue managers, Celery and RabbitMQ. It also explains how to build microservices and monitor tasks.

Chapter 7, Testing Microservices, provides complementary approaches for testing individual microservices and the entire microservice application. It also shows how to test a microservices application with Selenium automatically.

Chapter 8, Deploying Microservices with Docker, provides an overview of containerizing microservices with Docker and its benefits. It also demonstrates how to containerize microservices and set up a deployment cycle.

Chapter 9, Securing Microservices, shows how to secure microservices both from calling clients and microservices calling each other.

Chapter 10, Improving Microservices Performance with Caching, explains and demonstrates caching to maintain and improve microservices’ performance when user demand increases. Both Django’s built-in caching framework and Redis will be covered, including fully working samples.

Chapter 11, Best Practices for Microservices, provides hands-on tips and advice for optimally maintaining and running microservices. It addresses topics such as error handling, logging, and documenting.

Chapter 12, Transforming a Monolithic Web Application into a Microservices Version, walks through transforming an existing monolithic web application into a microservices version, as many Django developers will face this scenario.

To get the most out of this book

You need to have experience in developing Django applications. You don’t have to be a Django veteran with more than a decade of experience, but you should be able to create a Django application with forms. If you can create class-based forms and pages, it’s totally fine. A working knowledge of Flask or other Python web frameworks is also proficient. Furthermore, a basic understanding of Web APIs will help.

Software/hardware covered in the book

Operating system requirements

Django

Windows, macOS, or Linux

Redis

RabbitMQ

Celery

MongoDB Cloud version

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Hands-on-Microservices-with-Django/tree/main. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “This request applies the GET request to access the api.trip.com endpoint and addresses the hostels resource.”

A block of code is set as follows:

class AddressViewSet(viewsets.ModelViewSet):
    queryset = Address.objects.all()
    serializer_class = AddressSerializer

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

1 from rest_framework import generics
2 from .models import Address
3 from .serializers import AddressSerializer
4
5 class AddressList(generics.ListCreateAPIView):
6    queryset = Address.objects.all()
7    serializer_class = AddressSerializer
8
9 class AddressDetail(generics.
                       RetrieveUpdateDestroyAPIView):
10    queryset = Address.objects.all()
11    serializer_class = AddressSerializer

Any command-line input or output is written as follows:

$ curl -d '{"hostel_id":24, "start":"2024/03/01", "end":"2024/03/06"}' -H "Content-Type: application/json" -X POST http://api.trip/v1/hostels/

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “In the Name and Address fields, enter the values of your choice.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packtpub.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Hands-On Microservices with Django, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/978-1-83546-852-4

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon The rest of the chapter is locked
Next Chapter arrow right
You have been reading a chapter from
Hands-On Microservices with Django
Published in: May 2024 Publisher: Packt ISBN-13: 9781835468524
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}