46,44 €
Architect scalable, reliable, and maintainable applications for enterprises with Python
Key Features
Book Description
Dynamically typed languages like Python are continuously improving. With the addition of exciting new features and a wide selection of modern libraries and frameworks, Python has emerged as an ideal language for developing enterprise applications. Hands-On Enterprise Application Development with Python will show you how to build effective applications that are stable, secure, and easily scalable.
The book is a detailed guide to building an end-to-end enterprise-grade application in Python. You will learn how to effectively implement Python features and design patterns that will positively impact your application lifecycle. The book also covers advanced concurrency techniques that will help you build a RESTful application with an optimized frontend. Given that security and stability are the foundation for an enterprise application, you'll be trained on effective testing, performance analysis, and security practices, and understand how to embed them in your codebase during the initial phase. You'll also be guided in how to move on from a monolithic architecture to one that is service oriented, leveraging microservices and serverless deployment techniques.
By the end of the book, you will have become proficient at building efficient enterprise applications in Python.
What you will learn
Who this book is for
If you're a developer who wants to build enterprise-grade applications, this book is for you. Basic to intermediate-level of programming experience with Python and database systems is required to understand the concepts covered in this book.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 540
Veröffentlichungsjahr: 2018
Copyright © 2018 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.
Commissioning Editor: Aaron LazarAcquisition Editor: Chaitanya NairContent Development Editor: Manjusha MantriTechnical Editor:Ashi SinghCopy Editor: Safis EditingProject Coordinator:Prajakta NaikProofreader: Safis EditingIndexer:Mariammal ChettiyarGraphics: Jisha ChirayilProduction Coordinator:Jyoti Chauhan
First edition: December 2018
Production reference: 1271218
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-78953-236-4
www.packtpub.com
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.Packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.Packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Saurabh Badhwar is a developer and open source enthusiast who is passionate about improving software performance and scalability. He has been actively contributing to Mozilla Servo and Fedora Project in the fields of release engineering, quality assurance, and community building. He has given talks at various community organized events and universities to onboard and engage new members in the community. Saurabh is currently exploring the microservices architecture and has given various talks on it. His most recent talk on the microservices architecture happened at DevconfCZ 2018. Currently, Saurabh works as an Associate Software Engineer, Performance and Scale Engineering at Red Hat.
Zhuo Qingliang (also known online as KDr2) works at Beijing Paoding Tech (PAI), a start-up fintech company in China that is dedicated to improving the financial industry by using artificial intelligence technologies. He has over 10 years of experience in Linux, C, C++, Java, Python, and Perl development. He is interested in programming, consulting, and contributing to the open source community.
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Title Page
Copyright and Credits
Hands-On Enterprise Application Development with Python
About Packt
Why subscribe?
Packt.com
Contributors
About the author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Using Python for Enterprise
Technical requirements
Recent developments in Python
Dropping backward compatibility
It's all Unicode
Support for type hinting
Where Python shines
The requirements of enterprise IT
Python in the enterprise ecosystem
Introducing BugZot – a RESTful bug tracker
Gathering requirements before development
Asking for the user requirements
Categorizing the requirements
Prioritizing the requirements
Generating the software requirement specification document
Summary
Questions
Further reading
Design Patterns – Making a Choice
Technical Requirements
Design patterns
Classification of design patterns
Defining the choice of design patterns
Object-oriented Python
The basic OOP principles
Encapsulation
Composition
Inheritance
Multiple inheritance in Python
Method resolution order in multiple inheritance
Utilizing mixins
Abstract base classes
Metaclasses
The Singleton pattern
The __call__ magic method
The Factory pattern
The Model-View-Controller pattern
Controller
Model
View
Summary
Questions
Building for Large-Scale Database Operations
Technical requirements
Database and object relational mappers
Setting up SQLAlchemy
Building optimal database models
Issues with our model definition
Optimizing our models
Taking advantage of indexes
Maintaining database consistency
Utilizing transactions to maintain consistency
Understanding lazy loading versus eager loading
Using relationships
Lazy loading
Eager loading
Optimizing data loading
Utilizing caching
Caching at the database level
Caching at the block level
Using user-level caching
Summary
Questions
Dealing with Concurrency
Technical requirements
The need for concurrency
Concurrency in GUI applications
Concurrency in enterprise applications
Concurrent programming with Python
Concurrency with multithreading
Thread synchronization
Re-entrant locks
Condition variables
Common pitfalls with multithreading
Race conditions
Deadlocks
The story of GIL
Concurrency with multiprocessing
Python multiprocessing module
Synchronizing processes
Summary
Questions
Building for Large-Scale Request Handling
Technical requirements
The problems of accommodating increased concurrency
The multiple options to scale up
Engineering the application for scalability
Controlling the concurrency
Using thread pools for handling incoming connections
Asynchronous programming with AsyncIO
AsyncIO terminology
Event loop
Co-routines
Tasks
Writing a simple Python AsyncIO program
Implementing a simple socket server with AsyncIO
Boosting the application concurrency
Running behind a reverse proxy
Improved security
Improved connection handling
Resource caching
Serving static resources
Summary
Questions
Example – Building BugZot
Technical requirements
Defining the requirements
Entering the development phase
Setting up the development environment
Setting up the database
Setting up the virtual environment
Structuring our project
Initializing the Flask project
Creating the configuration
Developing database models
Migrating the database models
Building the views
Developing the index view
Getting the index view to render
Building the user registration view
Deploying for concurrent access
Setting up Gunicorn
Setting up Nginx as reverse proxy
Establishing communication between Nginx and Gunicorn
Summary
Questions
Building Optimized Frontends
Technical requirements
The need for optimizing frontends
Components of an optimized frontend
What causes frontend issues
Optimizing the frontend
Optimizing resources
Fetching CSS in parallel by avoiding CSS imports
Bundling JavaScript
Utilizing client-side caching
Setting application-wide cache control
Setting request level cache control
Utilizing web storage
Working with local web storage
Working with session storage
Summary
Questions
Writing Testable Code
Technical requirements
The importance of testing
The different kinds of testing
Unit testing
Integration testing
Building an application with testing in mind
Test-driven development
Writing unit tests
Writing unit tests with Python unittest
Writing unit tests with pytest
Let's set up pytest
Writing our first test with pytest
Writing functional tests with pytest
Summary
Questions
Profiling Applications for Performance
Technical requirements
Behind the scenes of performance bottlenecks
Looking at the causes of performance bottlenecks
Probing an application for performance issues
Writing performance benchmarks
Writing our first benchmark
Writing an API benchmark
Doing component-level performance analysis
Measuring slow operations with timeit
Profiling with cProfile
Profiling for memory usage with memory_profiler
Collecting live performance data
Logging performance metrics
Avoiding performance bottlenecks
Summary
Questions
Securing Your Application
Technical requirements
Enterprise application security
The importance of enterprise security
Challenges in system security
Taking a look at the attack vectors
Security issues with native applications
Security issues with web applications
Security anti-patterns
Not filtering user input
Storing Sensitive Data Unencrypted
Ignoring bound-checking
Not keeping the libraries updated
Giving full privileges of the database to a single user
Improving your application's security
Summary
Questions
Further reading
Taking the Microservices Approach
Technical requirements
The shift toward microservices
Monolithic development model versus microservices
Advantages of the microservices architecture
Guidelines for microservice development
Service-level agreements in microservices
Building your first microservices application
The user microservice
The to-do manager service
Service discovery in microservices
Service registry inside microservices
Client-side service discovery
Server-side service discovery
API gateways in microservices
Asynchronous communication in microservices
Message queues for microservices communication
Summary
Questions
Further reading
Testing and Tracing in Microservices
Technical requirements
Testing in the microservices world
Unit testing in microservices
Functionality testing in microservices
Integration testing in microservices
End-to-end testing in microservices
Scalability testing
Challenges in microservices testing
Tracing requests inside microservices
The OpenTracing standard
Implementing tracing inside ToDo manager
Distributed tracing
Benefits of distributed tracing
Summary
Questions
Going Serverless
Technical requirements
The serverless approach to application development
Components of serverless architecture
Backend as a service
Function as a service
The restrictions on state management
Restrictions on execution times
Executing functions inside FaaS
API gateways in the serverless architecture
Understanding the execution of a serverless application
Cold-starting a function
Hot-starting a function
Building our first serverless application
A quick introduction to Apache OpenWhisk
Setting up the development environment
Building our configuration file
Integrating with the GitHub API
Getting the code ready to run with OpenWhisk
Taking the final steps toward deployment
Deploying to OpenWhisk
Understanding the execution of application Inside Openwhisk
Advantages of going serverless
Summary
Questions
Further reading
Deploying to the Cloud
Technical requirements
Deploying enterprise applications
Making a choice about the deployment strategy
The different deployment strategies
Recreated deployments
Rolling deployments
Blue/green deployments
Canary deployments
A/B deployments
Shadow deployments
Making a choice of infrastructure
The traditional infrastructure
Containerized approach toward application packaging
The move toward the cloud
The different types of cloud deployments
Private clouds
Public clouds
Hybrid clouds
Summary
Questions
Enterprise Application Integration and its Patterns
Technical requirements
The need for EAI
Point-to-point integration
Moving towards EAI
The traditional approach to EAI
The introduction of the ESB
Patterns in EAI
Integration patterns
Mediation pattern
Federation pattern
Access patterns
Asynchronous access patterns
Synchronous access patterns
Issues in EAI
Summary
Questions
Microservices and Enterprise Application Integration
Technical requirements
Microservices and the changing EAI landscape
Challenges of traditional EAI in microservices
Point-to-point integration of microservices
Integrating microservices using the ESB
Utilizing API gateways for the integration of microservices
Transformation of the ESB
Rethinking EAI in microservices
Summary
Questions
Assessment
Chapter 1
Answer 1
Answer 2
Answer 3
Answer 4
Answer 5
Chapter 2
Answer 1
Answer 2
Answer 3
Chapter 3
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 4
Answer 1
Answer 2
Answer 3
Answer 4
Answer 5
Chapter 5
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 6
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 7
Answer 1
Answer 2
Answer 3
Chapter 8
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 9
Answer 1
Answer 2
Answer 3
Answer 4
Answer 5
Chapter 10
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 11
Answer 1
Answer 2
Answer 3
Answer 4
Answer 5
Chapter 12
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 13
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 14
Answer 1
Answer 2
Answer 3
Answer 4
Chapter 15
Answer 1
Answer 2
Answer 3
Chapter 16
Answer 1
Answer 2
Answer 3
Other Books You May Enjoy
Leave a review – let other readers know what you think
Python is a dynamically typed, interpreted language that facilitates the rapid building of applications in various areas of software development, including AI, desktop, and web applications.
With recent advancements in the Python ecosystem and the availability of a huge number of libraries that support high re-usability and enable the compilation of modular code, Python can be used to build applications that can solve an organization's problems. These applications can be developed in short timeframes and, if developed carefully, can allow them to be scaled in a manner that solves the needs of an organization.
Python version 3.7 brings with it several improvements and new features that make application development a breeze. Along with new features, improvements in the language's performance make it a good choice for building scalable, mission-critical applications powered by a choice of different runtimes based on the organization's needs.
An enterprise application is a critical application that aims to solve the specific business needs of an organization. The requirements of an enterprise application differ greatly from those that are usually needed by an individual. These applications are supposed to provide high performance and scalability to enable the increasing everyday needs of an organization.
Keeping this in mind, this book is intended for developers who have an intermediate knowledge of coding in Python and are willing to dive deeper into building applications that can be scaled up, based on the needs of the organization. The book provides several examples that can be executed on Python 3.7 running on Linux-based distributions, but which also work on other operating systems.
To make the best use of this book, you must have a basic understanding of fundamental operating system concepts, such as process management and multithreading. Beyond this, a basic working knowledge of database systems may be beneficial, although not mandatory.
Developers who are familiar with the different aspects of building applications in Python can get to learn about the tools and techniques that can help them build scalable applications and provide them with an idea of the enterprise application development approach.
This book contains 16 chapters organized into roughly 4 parts: an introduction to Python in enterprises; the testing, performance, and security of enterprise applications; the shift toward microservices; and enterprise application integration.
The first part covers the utilization of Python in enterprise application development and deals with the various aspects related to building a performant and scalable application with Python. This first part consists of seven chapters.
Chapter 1, Using Python for Enterprise Application Development, introduces the capabilities of Python that make it a rich language when it comes to developing enterprise applications and provides information about the changes that have happened in the Python ecosystem and how they have helped in boosting the utilization of Python within the community.
Chapter 2, Design Patterns – Making a Choice, explains the importance of design patterns in the development of applications and covers some of the commonly used design patterns in application development and how they can be implemented in Python. This chapter also provides guidance on how to choose which design patterns to use while developing the application.
Chapter 3, Building for Large-Scale Data Operations, covers how to build enterprise applications that can handle a large number of concurrent data operations while maintaining the consistency of data. This chapter takes a look at how the data models are developed to allow for scalability and performance and then goes on to provide information about how to make database operations efficient.
Chapter 4, Dealing with Concurrency, introduces us to the different ways in which we can improve the ability of our application to deal with concurrent workloads. For this, the chapter introduces us to various techniques in Python related to the implementation of multiprocessing and multithreading and how we can use them to boost the concurrency-managing capability of the application.
Chapter 5, Building for Large-Scale Request Handling, introduces us to the ways in which we can make our application scale well when it comes to a high number of concurrent users while keeping the response times adequate. We will also cover the different techniques related to maximizing the output from multithreading, utilizing asynchronous operations, and so on.
Chapter 6, Building BugZot, makes use of what we have learned in the preceding chapters to come up with an example application known as BugZot, which provides our dummy organization, Omega Corporation, with a bug tracking system. While building this application, we get to implement the techniques related to building efficient database models, implementing concurrency, and handling the uploading of large files.
Chapter 7, Building Optimized Frontends, takes us through the importance of building application frontends that are responsive and light on resources. This chapter covers various techniques related to the optimization of web-based frontends and how to provide an experience that keeps the user engaged with the application.
With this, we enter the second part of the book, which consists of three chapters aimed at improving the delivery aspects of the application.
Chapter 8, Writing Testable Code, focuses on the points related to the importance of writing code that can be tested easily and how it helps in delivering applications that are stable and robust when deployed in production. This chapter introduces us to a Python-based testing framework that can be used to write unit tests and integration tests and also covers the aspects of automated testing of the code.
Chapter 9, Profiling Application for Performance, introduces us to the tools and techniques that we, as developers, can use to build performance profiling into the core of the application to understand the performance implications of running the applications and allow us to uncover bottlenecks in production.
Chapter 10, Securing Your Applications, covers the different attack vectors that are used by attackers to compromise enterprise data security and then helps us to understand the basics of how we can avoid introducing vulnerabilities into our applications.
The third part of the book includes the following chapters that cover the architecture of application development.
Chapter 11, Taking the Microservices Approach, takes us on a journey of developing applications based on microservice architecture. In this chapter, we will take a look at what exactly microservice architecture is and the advantages it provides. We will then move on to understanding the different components that power microservice architecture and conclude by building a small application based on microservice principles.
Chapter 12, Testing and Tracing in Microservices, goes into how the move to microservices has changed the way we approach application testing, which now comprises the interaction of several small services instead of large components. We take a look at additional steps that might be required in making sure the applications work in the manner they are expected to, before we dive into another concept that allows us to trace the flow of the request in our application as it passes through different services.
Chapter 13, Going Serverless, introduces us to yet another method of building our applications where we, as developers, do not need to care about where the application will run and how it will scale. In this chapter, we will learn about how we can divide our application into functions that can run without our supervision and execute based on a set of events.
Chapter 14, Deploying to the Cloud, introduces us to the different cloud deployment strategies and how they can help us while also providing us with guidance about which type of cloud deployment to choose, based on the requirements of the organization.
The fourth and final part of the book includes the following chapters, which introduce us to the need to integrate different applications inside the enterprise.
Chapter 15, Enterprise Application Integration and their Patterns, takes us through an introduction to why enterprise application integration is necessary and how it was achieved in days gone by, before diving into the concepts of using middleware and an enterprise service bus. This chapter concludes with a discussion of various EAI patterns that are in use.
Chapter 16, Microservices and Enterprise Application Integration, takes us through the differences that the move toward microservices has introduced to the EAI landscape. In this chapter, we will take a look at how the modern concepts of microservices have changed how application integration was achieved in the past and how we can plan ahead for integrating different applications in this modern age.
Other than being familiar with programming in general, no particular specialist knowledge is expected in order to be able to take advantage of this book.
Odoo is built using Python, so it is a good idea to have a sound knowledge of the language. We also choose to run Odoo in an Ubuntu host (a popular cloud hosting option) and will do some work on the command line, so some familiarity will be beneficial.
To get the most out of this book, we recommend that you find complementary readings on the Python programming language, Ubuntu/Debian Linux operating system, and the PostgreSQL database.
Although we will run Odoo in an Ubuntu host, we will also provide guidance on how to set up our development environment in a Windows system with the help of VirtualBox. Of course, working from an Ubuntu/Debian system is also a possibility.
All the required software is freely available, and instructions on where to find it will be given.
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register at
www.packt.com
.
Select the
SUPPORT
tab.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box and follow the onscreen instructions.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-Enterprise-Application-Development-with-Python. We also have other code bundles from our rich catalog of books and videos available athttps://github.com/PacktPublishing/. Check them out!
Feedback from our readers is always welcome.
General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].
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.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
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 [email protected] 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.packt.com.
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.
Python has been around in the world of programming for more than two decades now, and over the years, the language has seen a number of refinements, a growing community, and a lot of production-ready and well-supported libraries. But is Python ready to make a dent in the world of enterprise application development, which has been long dominated by the likes of C++, Java, and .NET, the so-called enterprise-grade languages?
Over the course of this chapter, we will see how Python has evolved over the years and how it is ready to become a serious competitor in the world of enterprise application development.
This chapter will cover the following topics:
Recent developments in Python to enable its growth in enterprise application development
The special use cases where Python shines
The differences between enterprise and general-purpose software
The requirements for developing
an enterprise application
The code listings in this book can be found under chapter01 directory at https://github.com/PacktPublishing/Hands-On-Enterprise-Application-Development-with-Python.
The code samples can be cloned by running the following command:
git clone https://github.com/PacktPublishing/Hands-On-Enterprise-Application-Development-with-Python
The instructions to run the code can be found under the README file in the individual chapter directories.
The code has been tested to run on a system that is running Fedora 28 and Python version 3.6.5, but it should be able to run on any system running Python 3.6.5.
Python is a dynamically typed, interpreted language that was initially well suited for scripting tasks that are boring and repetitive day-to-day tasks. But as the years progressed, the language gained a number of new features and the huge backing of its community, which propelled its development to make it a language that is now well suited to performing tasks that range from very simple applications, such as web scraping, to analyzing large amounts of data for training machine learning models that themselves are written in Python. Let's take a look at some of the major things that have changed over the years and see what the latest release of Python, Python 3, brings to the table.
Python as a language has evolved a lot over the years, but despite this fact, a program written in Python 1.0 will still be able to run in Python 2.7, which is a version that was released 19 years after Python 1.0.
Though a great benefit for the developers of Python applications, this backward compatibility of the language is also a major hurdle in the growth and development of major improvements in the language specification, since a great amount of the older code base will break if major changes are made to the language specification.
With the release of Python 3, this chain of backward compatibility was broken. The language in version 3 dropped the support for programs that were written in earlier versions in favor of allowing a larger set of long-overdue improvements to the language. However, this decision disappointed quite a lot of developers in the community.
Every language has been developed to solve a certain type of problem that developers face while trying to build software for a specific domain. Python, being a dynamically typed, interpreted language, also has a set of use cases where it excels.
These use cases involve the automation of repetitive and boring tasks, quick prototyping of applications, and small applications focusing on accomplishing a specific goal, such as the installation of software, the setting up of a development environment, performing cleanup, and so on.
But is that all? Is Python good only for doing small tasks? The answer to this is no. Python as a language is much more powerful and can easily accomplish a large amount of increasingly complex tasks, such as running a website that scales to cope with millions of users using it in a very short span of time, processing large sets of incoming files, or training a machine learning model for an image-recognition system.
We are talking about achieving increasingly complex tasks using Python, but isn't Python slow compared to our traditional compile-time languages, such as C++, Java, and .NET? Well, that completely depends upon the context in which a person wants to use Python. If your aim is to run a Python program on an embedded device with only a limited amount of processing power, then yes, Python might be inadequate because of the sheer extra load that its interpreter will have on the processing environment. But if you are planning to use Python to run a web application on decently configured modern hardware, you might never experience any slowdowns while using Python. Rather, you might well feel a bit more productive while using it because of the sheer simplicity of its syntax and the ease of performing operations without writing hundreds of lines to achieve simple tasks.
So, let's see how Python fares in the enterprise environment.
Enterprise IT is complex, and an application that needs to be built for the enterprise will differ a lot from one that is built for a regular consumer. There are several factors that need to be kept in mind before developing an application for enterprise users. Let's take a look at what makes enterprise IT applications different from regular consumer offerings, as shown in the following list:
Business oriented
:
Unlike an application that is built to solve the problems of individual users, an enterprise application is built to meet the specific needs of an organization. This requires the application to conform to the business practices of the organization, the
ir rules, and the workflow they use.
Robustness at scale
: Most enterprises usually consist of thousands of employees who depend upon the internal applications to work and collaborate with each other. These kinds of use cases generate a large amount of data in various ways, and an application built for enterprise should be robust enough to handle thousands of users at the same time while also being able to crunch through a large amount of data that is distributed over a large network of nodes. During this time, the application should provide adequate mechanisms to deal with unexpected events that may happen for various reasons, such as attempts to breach security, the failure of nodes, power failure, and so on.
Long-term support
: An enterprise application needs to provide long-term support because enterprises usually don't want to move to newer applications as frequently as a regular consumer does. This happens because most enterprise applications are developed to integrate with the workflow of the organizations, and frequently changing an application will not only increase ownership costs for the enterprise, but will also cause a major disruption in the workflow for the employees of the organization.
Ability to integrate
:
Most of the applications that are built for the enterprise won't be running as standalone applications. They will frequently need to interface with the other applications inside the organization. This gives rise to the need to provide a mechanism for easy integration of the application with others in the organization.
As we progress through the chapters in this book, we will need some way to implement what we have learned.
Imagine that you work for an organization known as Omega Corporation, which is a market leader for selling software products to companies and individuals. Omega Corporation needs a system through which it can track the bugs in its products. After a lot of brainstorming, they initiate a project codenamed BugZot, which will be their tool to track the bugs in their products.
Let's take a look at what Omega Corporation wants to achieve with project BugZot:
Ability for users to report bugs in products: The users, be they internal or external, should be able to file bugs against a particular product of the organization, and while filing these bugs, the users should be able to select the release version of the product they are filing bugs against so as to provide increased granularity.
Ability to control who can see the bug details: Since the application allows both internal and external users to file bugs, it is possible that internal users, such as quality engineers or internal IT teams, may file bugs against a product that has not yet been made available to the customers. This will mean that BugZot should be able to hide the details about the bugs that have a confidential status.
Providing support for role-based permissions: BugZot should be able to support the concept of roles and permissions so that an unauthorized person cannot change the details of a particular bug. For example, we might not want an external customer to come and change the target release version for a bug, which is a task that should be done by product management.
Support for file uploads: When a bug is filed, usually an error report or a log file from the product greatly helps to drill down to the root cause. This will mean that BugZot should be able to deal with file uploads and link the uploaded files to their respective bugs.
Search functionality: A person using BugZot should be able to search for the bugs that are filed into the system based upon certain filter criteria, such as the identity of the user who filed the bugs, the current status of the bug, filing bugs against, and so on.
Integration with email: When a bug changes state—for example, if a bug is moved from NEW to ASSIGNED—there should be an email notifying the people associated with the bug. This will require BugZot to provide integration with the email service provider of Omega Corporation.
Ease of integration: Omega Corporation plans to extend the usage of BugZot at a later time by integrating BugZot with the various other internal applications they have. For this, BugZot should provide an easy way to achieve this integration.
Throughout the course of this book, we will be learning various concepts in Python and applying them to build BugZot, the bug-tracking system for Omega Corporation.
Gathering the software requirements before starting the development of an enterprise application can be a tedious task, and a failure to do so adequately can have severe consequences, such as increased costs due to delays that are caused by identifying requirements later in the development cycle of the application. Applications that lack the important features to improve the business process workflow will lead users to stop using the application in the worst case.
The requirement-gathering process is complex and tedious, and can take months to complete in an organization. Covering all the steps involved in the process is beyond the scope of this book. This section tries to give a brief description about some of the important steps in the process of gathering software requirements.
For an application inside an organization, there might be various users who are stakeholders, and can define the requirements of the application. These users can be broadly split into two categories:
The workforce: These are the users who usually use the application to achieve a certain set of tasks. They are not concerned with all the features provided by the application, but rather what they focus upon is how well the application fits into their individual workflows. These users can provide requirements specific to what they work on, but may not be able to provide ideas about what they might require in the future, or what the other teams may require.
The management: The management consists of people who understand the business process of the organization and have a much broader view ofwhat the application should be able to do. These users may not be able to define the requirements of a particular use case, but can provide requirements considering what the application should do now and what future features might be needed.
Involving both kinds of stakeholders in the requirement-gathering process is important, and something that will define how well the enterprise application meets the demands of its users.
Once the users have been surveyed for what they would like to have in the application, the next step is to categorize these requirements. Broadly, the requirements can be categorized into two parts:
Functional requirements: These are the requirements that define the features and functionality of the application. For example, BugZot has the following functional requirements:
Providing functionality for filing bugs by internal and external users
Providing support for roles and permissions
Providing functionality for dealing with file uploads
Integrating with the email system to send emails when a bug changes its status, and much more
Nonfunctional requirements: These are those sets of requirements that do not affect the functionality of the software, but rather are implicit or explicit characteristics based on the functional requirements. For example, in BugZot, the following may be defined as some of the nonfunctional requirements:
The application should provide security against common web attack vectors, such as XSS and CSRF
The operational costs for the application should not exceed
N
% of the total budget
The application should be able to generate backups in case a recovery is needed after a crash
Once the requirements are identified and categorized into functional and nonfunctional requirements, they then need to be prioritized according to their importance in the application. If this prioritization is not performed, it will lead to increased costs of development, delayed deadlines, and reduced productivity in the organization. Broadly, we can classify the requirements under the following categories:
Must have
:
These are those requirements that are critical to the success of the application and that must be present in the application when it ships.
Should have
:
These are those requirements that will enhance the functionality of the application but that need some further discussion about whether they should be added to the application.
Could have
:
These are those requirements that are mostly enhancements, and the presence or absence of which won't affect the functionality of the application. These requirements can be taken care of in later updates to the application.
Wish list
:
These are those requirements that are considered features that can be added at some later point in time, but which are not mission critical to the application. These features can be reviewed later for inclusion in the application update cycle.
Once the requirements have been identified, grouped, and prioritized, a document known as the software requirement specification is generated. This document describes the intended purpose, requirements, and nature of the software that needs to be developed.
The software requirement specification (SRS) will describe the following information:
The intended purpose of the applications
The conventions that are used in the document that are specific to the business process of the organization
The features of the application
The user classes who will be using the application
The environment in which the application will operate
The functional and nonfunctional requirements of the application
Once the SRS has been generated, it is sent for review and further negotiations. Once they are successfully completed, the application moves into the design phase, where an application mock-up is devised.
In this chapter, we briefly covered the changing programming landscape and explored how the Python ecosystem has changed over the years. We looked at how Python, given the fact that it allows quick prototyping, and has a vast array of well-supported libraries and an open community, is quickly rising to become the main choice for the development of large-scale applications in enterprises that require long-term support and easy integration with existing systems.
We then went on to introduce the demo application, BugZot, that we will be building throughout the course of this book, and defined the functionalities that will be required from the application.
The last section of the chapter covered the requirement-gathering process for developing an enterprise application in a brief, looking at the different stakeholders, such as the hands-on users and the management users, and categorizing the requirements into functional and nonfunctional requirements. We also looked at the importance of prioritizing the requirements.
With the basic knowledge of the environment with which we are going to work on during the course of the book, we are now ready to take a deep dive into the first important aspect of the Enterprise application development which deals with how we layout the code base of our application in production which involves, how a particular set of objects are created and utilized in the application while focusing on the increased re-usability of the modules. The next chapter focuses on this important aspect which is also known as the Design patterns and cover the different types of patterns and how they can be used during the development of your application.
Is it possible to perform operations such as concatenation on a
str
type and a
byte
type in Python 3?
Is the type hinting support introduced in Python 3 enforcing or not?
Beyond functional and nonfunctional requirements, are there any other kinds of requirements that also might need to be documented into the software requirement specification?
What are the major categories in which the prioritization of requirements can be done?
What are the next steps to take once the software requirement specification document has been generated?
If you would like to go through the basics of Python programming once again before diving into the world of enterprise application development, Packt has a very good book that you can be refer to. You can get it at the following link:
https://www.packtpub.com/application-development/learn-python-programming-second-edition
When a software application development project is taken up, it is essentially thought of as a problem that requires a solution. When we start to develop the application, we start developing a solution specific to the given problem. Eventually, this solution may start getting reused in problems of a similar kind, and becomes a standard solution for solving such problems. As time passes, we see that a lot of problems that display the same pattern. Once we modify our standard solution to work on this observed pattern, we come up with a design pattern. Design patterns are no joke; they take years to produce, after being tried and tested for solving a great number of problems with a similar pattern.
The design patterns not only define the way in which we architect our software application, they also provide knowledge about what worked and what did not, while trying to solve a particular type of problem. There are times when no particular design pattern might suit the needs of a particular application and the developers are left with no choice but to come up with something unique.
Are there some existing standard design patterns that can be used for a particular type of problem? How can we decide which design pattern to use for our problem? Can we deflect from a particular design pattern and use them while working on our solution? We will try to answer these questions as we progress through the chapter.
By the end of this chapter, you will know about the following:
Design patterns and their classification
The object-oriented nature of Python, and how we can use it to implement some common design patterns
Use cases where a particular pattern may be used
The code listings in this book can be found under chapter02 directory at https://github.com/PacktPublishing/Hands-On-Enterprise-Application-Development-with-Python.
The code samples can be cloned by running the following command:
git clone https://github.com/PacktPublishing/Hands-On-Enterprise-Application-Development-with-Python
The instructions to run the code samples can be found under the README.md file present inside the chapter directory.
A design pattern defines a way in which we can organize our solution to a given problem. It does not define algorithms that can be used to solve the problem, but rather provides an abstraction about how, for example, the code should be organized, what classes need to be defined, what their granularity will be, and how the different objects will be created.
The design patterns have gained a lot of traction, and the book Design Patterns: Elements of Reusable Object-Oriented Software, though published in 1994, still serves as a de facto reference when trying to understand design patterns.
A design pattern will usually consist of the following elements:
A problem statement
: A problem statement describes what we want to solve and hence also defines the design patterns we can use. The problem statement will tell us about the scope of the design that we are planning to pursue, the constraints that we may need to take care of, and at times how the different components will communicate with each other in the application.
The solution
:
A solution describes the design that makes up for the problem. It goes into detail about how the class hierarchies should be formed, how the objects will be formed, the relationship between the objects, and how the communication will take place between the different components. The solution will be an abstract design, not specifying the details of the implementation. This makes the solution generic, to be applied to a class of problems, without caring about what algorithms should be used to solve
a
particular problem.
The consequences
:
In the world of software development, nothing comes for free. Everything has a cost, and we trade off one thing for another.
