Akos Hochrein
Designing Microservices with Django
An Overview of Tools and Practices
Akos Hochrein
Berlin, Germany
Any source code or other supplementary material referenced by the author
in this book is available to readers on GitHub via the book’s product page,
located at www. apress. com/ 978-1-4842-5357-1 . For more detailed
information, please visit http:// www. apress. com/ source-code .
ISBN 978-1-4842-5357-1
https://doi.org/10.1007/978-1-4842-5358-8
e-ISBN 978-1-4842-5358-8
© Akos Hochrein 2019
Apress Standard
Trademarked names, logos, and images may appear in this book. Rather
than use a trademark symbol with every occurrence of a trademarked name,
logo, or image we use the names, logos, and images only in an editorial
fashion and to the benefit of the trademark owner, with no intention of
infringement of the trademark. The use in this publication of trade names,
trademarks, service marks, and similar terms, even if they are not identified
as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and
accurate at the date of publication, neither the authors nor the editors nor
the publisher can accept any legal responsibility for any errors or omissions
that may be made. The publisher makes no warranty, express or implied,
with respect to the material contained herein.
Distributed to the book trade worldwide by Springer Science+Business
Media New York, 233 Spring Street, 6th Floor, New York, NY 10013.
Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science +
Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For my aunts
Introduction
Welcome toDesigning Microservices with Django . I decided to grab a pen
and write this book because it was quite difficult for me to find easily
digestible guides on how to design microservices, including some of the
problems I might face along the way and the potential solutions to them.
I kick off this book by clarifying some of the terminology regarding
service design. Together, we look at a couple of anecdotes that will help us
understand the benefits and drawbacks of certain systems.
After that, we dive into Django development and develop an application
for ourselves that we talk about later in the book. We examine various high-
level concepts such as templates and view functions, in addition to lower
level ones, such as permissions and user management.
Now armed with knowledge of Django development, we delve deeply
into the different types of microservices and the high-level design principles
we should follow when we design them. We also take a look at
communication principles, such as REST (from the synchronous world) and
AMQP (from the asynchronous world), to achieve an understanding of how
these protocols work and which ones solve which sorts of problems.
Armed with microservice design knowledge, we study the
methodologies and techniques of migrating code into smaller systems.
To close, we look at how we can scale our development by making tools
that make microservices possible to all developers in a company. I hope you
are excited about this journey. I certainly am; so let’s get started!
Acknowledgments
Writing down thoughts and creating a book is quite a difficult endeavor, and
it requires a lot of people and luck to get it done. Luckily, I’ve had both on
my side.
This is the place where I thank the entire Django community for being
there and developing the basis of this book. Thank you! Stay awesome!
A thank you is in order to the publisher for helping me along the way
and making sure I kept progressing even when I felt like no progress was
being made. Thank you.
A big thank you is in order for the technical reviewers, Balázs and
Csaba. They kept me focused and gave me great feedback on the direction
and the contents of the book. They also aided me throughout my career to
get to this point, for which I will always be grateful. Thank you! You are
truly my friends.
I thank my friends here in Berlin and back in Budapest who kept me
sane and pushed me through all the creative blocks I had throughout the
writing process, even when I needed you to pay for the beer. Thank you.
You know who you are.
Thanks need to go to my family as well, who encouraged me to follow
my dreams and pushed me through difficult times in my life. Thanks Mom,
Dad, and Zalán. I’m lucky to have you in my life.
Table of Contents
Chapter 1: What are services?
Service Lingo
Software as a Service
Service-oriented Architecture
Monolithic Service
Microservice
Understanding the Monolith
Understanding the Microservice
Early Design Choices
Summary
Chapter 2: A Pinch of Django
Introducing the Problem
Getting Started
Django Apps
Models and the Power of ORMs
What are ORMs?
The Pizza
Migrations
Simple ORM Examples
Communication with Views
The Admin Panel
Logging in, Logging Out and Signing up
Signing up
Login and Logout
A Primer on Middlewares