Software Architecture with Python - Anand Balachandran Pillai - E-Book

Software Architecture with Python E-Book

Anand Balachandran Pillai

0,0
39,59 €

-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 starts by explaining how Python fits into an application's architecture. As you move along, you will get to grips with architecturally significant demands and how to determine them. Later, you’ll gain a complete understanding of the different architectural quality requirements for building a product that satisfies business needs, such as maintainability/reusability, testability, scalability, performance, usability, and security.

You will also use various techniques such as incorporating DevOps, continuous integration, and more to make your application robust. You will discover when and when not to use object orientation in your applications, and design scalable applications.

The focus is on building the business logic based on the business process documentation, and understanding which frameworks to use and when to use them. The book also covers some important patterns that should be taken into account while solving design problems, as well as those in relatively new domains such as the Cloud.

By the end of this book, you will have understood the ins and outs of Python so that you can make critical design decisions that not just live up to but also surpassyour clients’ expectations.

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

EPUB
MOBI

Seitenzahl: 591

Veröffentlichungsjahr: 2017

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.



Table of Contents

Software Architecture with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Principles of Software Architecture
Defining software architecture
Software architecture versus design
Aspects of software architecture
Characteristics of software architecture
An architecture defines a structure
An architecture picks a core set of elements
An architecture captures early design decisions
An architecture manages stakeholder requirements
An architecture influences the organizational structure
An architecture is influenced by its environment
An architecture documents the system
An architecture often conforms to a pattern
Importance of software architecture
System versus enterprise architecture
Architectural quality attributes
Modifiability
Testability
Scalability
Performance
Availability
Security
Deployability
Summary
2. Writing Modifiable and Readable Code
What is modifiability?
Aspects related to modifiability
Understanding readability
Python and readability
Readability – antipatterns
Techniques for readability
Document your code
Follow coding and style guidelines
Review and refactor code
Commenting the code
Fundamentals of modifiability – cohesion and coupling
Measuring cohesion and coupling
Measuring cohesion and coupling – string and text processing
Exploring strategies for modifiability
Providing explicit interfaces
Reducing two-way dependencies
Abstract common services
Using inheritance techniques
Using late binding techniques
Metrics – tools for static analysis
What are code smells?
Cyclomatic complexity – the McCabe metric
Testing for metrics
Running static checkers
Refactoring code
Refactoring code – fixing complexity
Refactoring code – fixing code smells
Refactoring code – fixing styling and coding issues
Summary
3. Testability – Writing Testable Code
Understanding testability
Software testability and related attributes
Testability – architectural aspects
Testability – strategies
Reduce system complexity
Improving predictability
Control and isolate external dependencies
White-box testing principles
Unit testing
Unit testing in action
Extending our unit test case
Nosing around with nose2
Testing with py.test
Code coverage
Measuring coverage using coverage.py
Measuring coverage using nose2
Measuring coverage using pytest
Mocking things up
Tests inline in documentation – doctests
Integration tests
Test automation
Test automation using Selenium WebDriver
Test-driven development
TDD with palindromes
Summary
4. Good Performance is Rewarding!
What is performance?
Software performance engineering
Performance testing and measurement tools
Performance complexity
Measuring performance
Measuring time using a context manager
Timing code using the timeit module
Measuring the performance of our code using timeit
Finding out time complexity – graphs
Measuring CPU time with timeit
Profiling
Deterministic profiling
Profiling with cProfile and profile
Prime number iterator class – performance tweaks
Profiling – collecting and reporting statistics
Third-party profilers
Line profiler
Memory profiler
Substring (subsequence) problem
Other tools
objgraph
Pympler
Programming for performance – data structures
Mutable containers – lists, dictionaries, and sets
Lists
Dictionaries
Sets
Immutable containers – tuples
High performance containers – the collections module
deque
defaultdict
OrderedDict
Dropping duplicates from a container without losing the order
Implementing a Least Recently Used (LRU) cache dictionary
Counter
ChainMap
namedtuple
Probabilistic data structures – bloom filters
Summary
5. Writing Applications that Scale
Scalability and performance
Concurrency
Concurrency versus parallelism
Concurrency in Python – multithreading
Thumbnail generator
Thumbnail generator – producer/consumer architecture
Thumbnail generator – resource constraint using locks
Thumbnail generator – resource constraint using semaphores
Resource constraint – semaphore versus lock
Thumbnail generator – URL rate controller using conditions
Multithreading – Python and GIL
Concurrency in Python – multiprocessing
A primality checker
Sorting disk files
Sorting disk files – using a counter
Sorting disk files – using multiprocessing
Multithreading versus multiprocessing
Concurrecy in Python – Asynchronous Execution
Pre-emptive versus cooperative multitasking
The asyncio module in Python
Waiting for a future – async and await
Concurrent futures – high-level concurrent processing
Disk thumbnail generator
Concurrency options – how to choose?
Parallel processing libraries
Joblib
PyMP
Fractals – the Mandelbrot set
Fractals – scaling the Mandelbrot set implementation
Scaling for the web
Scaling workflows – message queues and task queues
Celery – a distributed task queue
The Mandelbrot set using Celery
Serving with Python on the Web – WSGI
uWSGI – WSGI middleware on steroids
Gunicorn – unicorn for WSGI
Gunicorn versus uWSGI
Scalability architectures
Vertical scalability architectures
Horizontal scalability architectures
Summary
6. Security – Writing Secure Code
Information security architecture
Secure coding
Common security vulnerabilities
Is Python secure?
Reading input
Evaluating arbitrary input
Overflow errors
Serializing objects
Security issues with web applications
Server Side Template Injection
Server-Side Template Injection – Mitigation
Denial of Service
Cross-Site Scripting (XSS)
Mitigation – DoS and XSS
Strategies for security – Python
Secure coding strategies
Summary
7. Design Patterns in Python
Design patterns – elements
Categories of design patterns
Pluggable hashing algorithms
Summing up pluggable hashing algorithm
Patterns in Python – creational
The Singleton pattern
The Singleton – do we need a Singleton?
State sharing – Borg versus Singleton
The Factory pattern
The Prototype pattern
Prototype – deep versus shallow copy
Prototype using metaclasses
Combining patterns using metaclasses
The Prototype factory
The Builder pattern
Patterns in Python – structural
The Adapter pattern
The Facade pattern
Facades in Python
The proxy pattern
An instance-counting proxy
Patterns in Python – behavioral
The Iterator pattern
The Observer pattern
The State pattern
Summary
8. Python – Architectural Patterns
Introducing MVC
Model Template View (MTV) – Django
Django admin – automated model-centric views
Flexible Microframework – Flask
Event-driven programming
Chat server and client using I/O multiplexing with the select module
Event-driven programming versus concurrent programming
Twisted
Twisted – a simple web client
Chat server using Twisted
Eventlet
Greenlets and Gevent
Microservice architecture
Microservice frameworks in Python
Microservices example – restaurant reservation
Microservices – advantages
Pipe and Filter architectures
Pipe and filter in Python
Summary
9. Deploying Python Applications
Deployability
Factors affecting deployability
Tiers of software deployment architecture
Software deployment in Python
Packaging Python code
PIP
Virtualenv
Virtualenv and pip
Relocatable virtual environments
PyPI
Packaging and submission of an application
The __init__.py files
The setup.py file
Installing the package
Submitting the package to PyPI
PyPA
Remote deployments using Fabric
Remote deployments using Ansible
Managing remote daemons using Supervisor
Deployment – patterns and best practices
Summary
10. Techniques for Debugging
Maximum subarray problem
The power of "print"
Analysis and rewrite
Timing and optimizing the code
Simple debugging tricks and techniques
Word searcher program
Word searcher program – debugging step 1
Word searcher program – debugging step 2
Word searcher program – final code
Skipping blocks of code
Stopping execution
External dependencies – using wrappers
Replacing functions with their return value/data (mocking)
Saving to / loading data from files as cache
Saving to / loading data from memory as cache
Returning random/mock data
Generating random patient data
Logging as a debugging technique
Simple application logging
Advanced logging – logger objects
Advanced logging – custom formatting and loggers
Advanced logging – writing to syslog
Debugging tools – using debuggers
A debugging session with pdb
Pdb – similar tools
iPdb
Pdb++
Advanced debugging – tracing
The trace module
The lptrace program
System call tracing using strace
Summary
Index

Software Architecture with Python

Software Architecture with Python

Copyright © 2017 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, and its dealers and distributors will be held liable for any damages caused or alleged to be 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.

First published: April 2017

Production reference: 2060619

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78646-852-9

www.packtpub.com

Credits

Author

Anand Balachandran Pillai

Reviewer

Mike Driscoll

Commissioning Editor

Aaron Lazar

Acquisition Editor

Vinay Argekar

Content Development Editor

Rohit Kumar Singh

Technical Editors

Leena Patil

Vibhuti Gawde

Copy Editor

Sonia Mathur

Project Coordinator

Vaidehi Sawant

Proofreader

Safis Editing

Indexer

Mariammal Chettiyar

Graphics

Abhinash Sahu

Production Coordinator

Arvindkumar Gupta

About the Author

Anand Balachandran Pillai is an Engineering and Technology professional with over 18 years of experience in the software industry in Product Engineering, Software Design and Architecture and Research. He has a Bachelor's degree in Mechanical Engineering from the Indian Institute of Technology, Madras.

He has worked at companies such as Yahoo!, McAfee, and Infosys in the roles of Lead Engineer and Architect in product development teams, to build new products.

His interests lie in Software Performace Engineering, High Scalability Architectures, Security and open source communities. He often works with startups in lead technical or consulting role.

He is the founder of the Bangalore Python Users Group and a Fellow of the Python Software Foundation (PSF).

Anand is currently working as Senior Architect of Yegii Inc.

Dedicated to friends & family

About the Reviewer

Mike Driscoll has been programming in Python since 2006. He enjoys writing about Python in his blog, http://www.blog.pythonlibrary.org/. He has coauthored the Core Python refcard for DZone. He has also worked as a technical reviewer for Python 3 Object Oriented Programming, Python 2.6 Graphics Cookbook, Tkinter GUI Application Development Hotshot, and several other book. He recently wrote the book Python 101 and is working on his next book.

I would like to thank my beautiful wife, Evangeline, for always supporting me and my friends and family for all that they do to help me. And I would like to thank Jesus Christ for saving me.

www.PacktPub.com

For support files and downloads related to your book, please visit www.PacktPub.com.

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.PacktPub.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.PacktPub.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.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

Customer Feedback

Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1786468522.

If you'd like to join our team of regular reviewers, you can e-mail us at <[email protected]>. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!

Preface

Software architecture, or creating a blueprint design for a particular software application, is not a walk in the park. The two biggest challenges in software architecture are keeping the architecture in sync, first with the requirements as they are uncovered or evolve, and next with the implementation as it gets built and evolves.

Filled with examples and use cases, this guide takes a direct approach to helping you with everything it takes to become a successful software architect. This book will help you understand the ins and outs of Python so that you can architect and design highly scalable, robust, clean, and performant applications in Python.

What this book covers

Chapter 1, Principles of Software Architecture, introduces the topic of software architecture, giving you a brief on architectural quality attributes and the general principles behind them. This will enable you to have strong fundamentals in software architectural principles and foundational attributes.

Chapter 2, Writing Modifiable and Readable Code, covers developmental architectural quality attributes, namely, modifiability and readability. It will help you gain an understanding of the architectural quality attribute of maintainability and tactics of writing code in Python to test your applications.

Chapter 3, Testability – Writing Testable Code, helps you understand the architectural quality attribute of testability and how to architect Python applications for testability. You will also learn about various aspects of testability and software testing and the different libraries and modules available in Python to write testable applications.

Chapter 4, Good Performance is Rewarding!, covers the performance aspects of writing Python code. You will be equipped with the knowledge of performance as a quality attribute in architecture and when to optimize for performance. You will learn when to optimize for performance in the SDLC.

Chapter 5, Writing Applications that Scale, talks about the importance of writing scalable applications. It discusses different ways to achieve of application scalability and discusses scalability techniques using Python. You will also learn about theoretical aspects of scalability and the best practices in the industry.

Chapter 6, Security – Writing Secure Code, discusses the security aspect of architecture and teaches you best practices and techniques of writing applications that are secure. You will understand the different security issues to watch out for and to and to architecture applications in Python that are secure from the ground up.

Chapter 7, Design Patterns in Python, gives you an overview of design patterns in Python from a pragmatic programmer's perspective, with brief theoretical background of each pattern. You will gain knowledge of design patterns in Python that are actually useful to pragmatic programmer.

Chapter 8, Python Architectural Patterns, introduces you to the modern architectural patterns in Python from a high-level perspective while giving examples of Python libraries and frameworks to realize the approaches of these patterns to solve high-level architecture problems.

Chapter 9, Deploying Python Applications, covers the aspect of easily deploying your code on remote environments or on the cloud using Python the right way.

Chapter 10, Techniques for Debugging, covers some of the debugging techniques for Python code—from the simplest, strategically placed print statement to logging and system call tracing which will be very handy to the programmer and also help the system architect to guide his team.

What you need for this book

To run most of the code samples shown in this book, you need to have Python 3 installed on your system. The other prerequisites are mentioned at the respective instances.

Who this book is for

This book is for experienced Python developers who are aspiring to become the architects of enterprise-grade applications or software architects who would like to leverage Python to create effective blueprints of applications.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Software-Architecture-with-Python. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/SoftwareArchitecturewithPython_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Principles of Software Architecture

This is a book on Python. At the same time, it is a book about software architecture and its various attributes, which are involved in a software development life cycle.

In order for you to understand and combine both aspects, which is essential to get maximum value from this book, it is important to grasp the fundamentals of software architecture, the themes and concepts related to it, and the various quality attributes of software architecture.

A number of software engineers, taking on senior roles in their organizations, often get very different interpretations of the definitions of software design and architecture, and the roles they play in building testable, maintainable, scalable, secure, and functional software.

Though there is a lot of literature in the field, which is available both in conventional book form and on the internet; very often, the practitioners among us get a confusing picture of these very important concepts. This is often due to the pressures involved in learning the technology rather than learning the fundamental design and architectural principles underlying the use of technology in building systems. This is a common practice in software development organizations, where the pressures of delivering working code often overpowers and eclipses everything else.

A book such as this one, strives to transcend the middle path in bridging the rather esoteric aspects of software development related to its architectural quality attributes to the mundane details of building software using programming languages, libraries, and frameworks—in this case, using Python and its developer ecosystem.

The role of this introductory chapter is to demystify these concepts, and explain them in very clear terms to the reader to prepare his/her for the path towards understanding the rest of this book. Hopefully, by the end of this book, the concepts and their practical details will represent a coherent body of knowledge to the reader.

We will now get started on this path without any further ado, roughly fitting this chapter into the following sections:

Defining software architectureSoftware architecture versus designAspects of software architectureCharacteristics of software architectureWhy is software architecture important?System versus Enterprise ArchitectureArchitectural quality attributes
ModifiabilityTestabilityScalability/performanceSecurityDeployability

Defining software architecture

There are various definitions of software architecture in the literature concerning the topic. A simple definition is given as follows:

Software architecture is a description of the subsystems or components of a software system, and the relationships between them.

The following is a more formal definition, from the Recommended Practice for Architectural Description of Software-Intensive Systems (IEEE) technology:

"Architecture is the fundamental organization of a system embodied in its components, their relationships to each other, and to the environment, and the principles guiding its design and evolution."

It is possible to get umpteen such definitions of software architecture if one spends some time searching on the web. The wordings might differ, but all the definitions refer to some core, fundamental aspects underlying software architecture.

Software architecture versus design

In the experience of the author, this question of the software architecture of a system versus its design seems to pop up quite often, in both online as well as offline forums. Hence, let us take a moment to understand this aspect.

Though both terms are often used interchangeably, the rough distinction of architecture versus design can be summarized as follows:

Architecture covers the higher level structures and interactions in a system. It is concerned with those questions that entail decision making about the skeleton of the system, involving not only its functional but also its organizational, technical, business, and quality attributes.Design is all about the organization of parts or components of the system and the subsystems involved in making the system. The problems here are typically closer to the code or modules in question, such as these:
Which modules to split code into? How to organize them?Which classes (or modules) to assign the different functionalities to?Which design pattern should I use for class "C"?How do my objects interact at runtime? What are the messages passed, and how is the interaction organized?

Software architecture is about the design of the entire system, whereas, software design is mostly about the details, typically at the implementation level of the various subsystems and components that make up those subsystems.

In other words, the word design comes up in both contexts, however, with the distinction that the former is at a much higher abstraction and at a larger scope than the latter.

There is a rich body of knowledge available for both software architecture and design, namely, architectural patterns and design patterns respectively. We will discuss both these topics in later chapters of this book.

Aspects of software architecture

In both the formal IEEE definition and the rather informal definition given earlier, we find some common, recurring themes. It is important to understand them in order to take our discussion on software architecture further:

System: A system is a collection of components organized in specific ways to achieve a specific functionality. A software system is a collection of such software components. A system can often be subgrouped into subsystems.Structure: A structure is a set of elements that are grouped or organized together according to a guiding rule or principle. The elements can be software or hardware systems. A software architecture can exhibit various levels of structures depending on the observer's context.Environment: The environment is the context or circumstances in which a software system is built, which has a direct influence on its architecture. Such contexts can be technical, business, professional, operational, and so on.Stakeholder: A stakeholder is a person or groups of persons, who has an interest or concern in the system and its success. Examples of stakeholders are the architect, development team, customer, project manager, marketing team, and others.

Now that you have understood some of the core aspects of software architecture, let us briefly list some of its characteristics.

Characteristics of software architecture

All software architectures exhibit a common set of characteristics. Let us look at some of the most important ones here.

An architecture defines a structure

An architecture of a system is best represented as structural details of the system. It is a common practice for practitioners to draw the system architecture as a structural component or class diagram in order to represent the relationships between the subsystems.

For example, the following architecture diagram describes the backend of an application that reads from a tiered database system, which is loaded using an ETL process:

Example architecture diagram showing system structure

Structures provide insight into architectures, and provide a unique perspective to analyze the architecture with respect to its quality attributes.

Some examples are as follows:

The runtime structures, in terms of the objects created at runtime, and how they interact often determine the deployment architecture. The deployment architecture is strongly connected to the quality attributes of scalability, performance, security, and interoperability.The module structures, in terms of how the code is broken down and organized into modules and packages for task breakdown, often has a direct bearing on the maintainability and modifiability (extensibility) of a system. This is explained as follows:
Code which is organized with a view to extensibility would often keep the parent classes in separate well-defined packages with proper documentation and configuration, which are then easily extensible by external modules, without the need to resolve too many dependencies.Code which is dependent on external or third-party developers (libraries, frameworks, and the like) would often provide setup or deployment steps, which manually or automatically pull in these dependencies from external sources. Such code would also provide documentation (README, INSTALL, and so on) which clearly documents these steps.

An architecture picks a core set of elements

A well-defined architecture clearly captures only the core set of structural elements required to build the core functionality of the system, and which have a lasting effect on the system. It does not set out to document everything about every component of the system.

For example, an architect describing the architecture of a user interacting with a web server for browsing web pages—a typical client/server architecture—would focus mainly on two components: the user's browser (client) and the remote web server (server), which form the core elements of the system.

The system may have other components such as multiple caching proxies in the path from the server to the client, or a remote cache on the server which speeds up web page delivery. However, this is not the focus of the architecture description.

An architecture captures early design decisions

This is a corollary to the characteristics described previously. The decisions that help an architect to focus on some core elements of the system (and their interactions) are a result of the early design decisions about a system. Thus, these decisions play a major role in further development of the system due to their initial weight.

For example, an architect may make the following early design decisions after careful analysis of the requirements for a system:

The system will be deployed only on Linux 64-bit servers, since this satisfies the client requirement and performance constraintsThe system will use HTTP as the protocol for implementing backend APIsThe system will try to use HTTPS for APIs that transfer sensitive data from the backend to frontend using encryption certificates of 2,048 bits or higherThe programming language for the system would be Python for the backend, and Python or Ruby for the frontend

Note

The first decision freezes the deployment choices of the system to a large extent to a specific OS and system architecture. The next two decisions have a lot of weight in implementing the backend APIs. The last decision freezes the programming language choices for the system.

Early design decisions need to be arrived at after careful analysis of the requirements and matching them with the constraints—such as organizational, technical, people, and time constraints.

An architecture manages stakeholder requirements

A system is designed and built, ultimately, at the behest of its stakeholders. However, it is not possible to address each stakeholder requirement to its fullest due to an often contradictory nature of such requirements. Following are some examples:

The marketing team is concerned with having a full-featured software application, whereas, the developer team is concerned with feature creep and performance issues when adding a lot of features.The system architect is concerned with using the latest technology to scale out his/her deployments to the cloud, while the project manager is concerned about the impact such technology deployments will have on his/her budget. The end user is concerned about correct functionality, performance, security, usability, and reliability, while the development organization (architect, development team, and managers) is concerned with delivering all these qualities while keeping the project on schedule and within budget.A good architecture tries its best to balance out these requirements by making trade-offs, and delivering a system with good quality attributes while keeping the people and resource costs within limits.An architecture also provides a common language among the stakeholders, which allows them to communicate efficiently via expressing these constraints, and helping the architect zero-in on an architecture that best captures these requirements and their trade-offs.

An architecture influences the organizational structure

The system structures an architecture describes, quite often have a direct mapping to the structure of the teams that build those systems.

For example, an architecture may have a data access layer which describes a set of services that read and write large sets of data—it is natural that such a system gets functionally assigned to the database team, which already has the required skill sets.

Since the architecture of a system is its best description of the top-down structures, it is also often used as the basis for the task-breakdown structures. Thus, software architecture often has a direct bearing on the organizational structures that build it:

System architecture for a search web application

The following diagram shows the mapping to the team structure which would be building this application:

An architecture is influenced by its environment

An environment imposes outside constraints or limits within which an architecture must function. In the literature, these are often called architecture in context [Ref: Bass, Kazman]. Some examples are as follows:

Quality attribute requirements: In modern day web applications, it is very common to specify the scalability and availability requirements of the application as an early technical constraint, and capture it in the architecture. This is an example of a technical context from a business perspective.Standards conformance: In some organizations where there is often a large set of governing standards for software, especially those in the banking, insurance, and health-care domains, these get added to the early constraints of the architecture. This is an example of an external technical context.Organizational constraints: It is common to see that organizations which either have an experience with a certain architectural style or a set of teams operating with certain programming environments which impose such a style (J2EE is a good example), prefer to adopt similar architectures for future projects as a way to reduce costs and ensure productivity due to current investments in such architectures and related skills. This is an example of an internal business context.Professional context: An architect's set of choices for a system's architecture, aside from these outside contexts, is mostly shaped from his/her set of unique experiences. It is common for an architect to continue using a set of architectural choices that he/she has had the most success with in his/her past, for new projects.

Architecture choices also arise from one's own education and professional training, and also from the influence of one's professional peers.

An architecture documents the system

Every system has an architecture, whether it is officially documented or not. However, properly documented architectures can function as an effective documentation for the system. Since an architecture captures the system's initial requirements, constraints, and stakeholder trade-offs, it is a good practice to document it properly. The documentation can be used as a basis for training later on. It also helps in continued stakeholder communication, and for subsequent iterations of the architecture based on changing requirements.

The simplest way to document an architecture is to create diagrams for the different aspects of the system and organizational architecture such as Component Architecture, Deployment Architecture, Communication Architecture, and the Team or Enterprise Architecture.

Other data that can be captured early include the system requirements, constraints, early design decisions, and rationale for those decisions.

An architecture often conforms to a pattern

Most architectures conform to certain sets of styles which have had a lot of success in practice. These are referred to as architectural patterns. Examples of such patterns are client-server, pipes and filters, data-based architectures, and others. When an architect chooses an existing pattern, he/she gets to refer to and reuse a lot of existing use cases and examples related to such patterns. In modern day architectures, the job of the architect comes down to mixing and matching existing sets of such readily available patterns to solve the problem at hand.

For example, the following diagram shows an example of a client-server architecture:

Example of client-server architecture

The following diagram describes another common architecture pattern, namely, the pipes and filters architecture for processing streams of data:

Example of pipe and filters architecture

We will see examples of architectural patterns later in this book.

Importance of software architecture

So far, we have discussed the fundamental principles of software architecture, and also seen some of its characteristics. These sections, of course, assumed that software architecture is important, and is a critical step of the software development process.

It is time to play devil's advocate, and look back at software architecture and ask some existential questions about it as follows:

Why software architecture?Why is software architecture important?Why not build a system without a formal software architecture?

Let us take a look at the critical insights that software architecture provides, which would otherwise be missing from an informal software development process. We are only focusing on the technical or developmental aspects of the system in the following table:

Aspect

Insight/Impact

Examples

Architecture selects quality attributes to be optimized for a system.

Aspects such as scalability, availability, modifiability, security, and so on of a system depend on early decisions and trade-offs while selecting an architecture. You often trade one attribute in favor of another.

A system that is optimized for scalability must be developed using a decentralized architecture where elements are not tightly coupled. For example: microservices, brokers.

Architecture facilitates early prototyping.

Defining an architecture allows the development organization to try and build early prototypes, which gives valuable insights into how the system would behave without having to build the complete system top down.

Many organizations build out quick prototypes of services—typically, by building only the external APIs of these services and mocking the rest of the behavior. This allows for early integration tests and figuring out interaction issues in the architecture early on.

Architecture allows a system to be built component-wise.

Having a well-defined architecture allows the reuse and assembly of existing, readily available components to achieve the functionality without having to implement everything from scratch.

Libraries or frameworks which provide ready-to-use building blocks for services.

For example: web application frameworks such as Django/RoR, and task distribution frameworks such as Celery.

Architecture helps to manage changes to the system.

An architecture allows the architect to scope out changes to the system in terms of components that are affected and those which are not. This helps to keep system changes to a minimum when implementing new features, performance fixes, and so on.

A performance fix for database reads to a system would need changes only to the DB and Data Access Layer (DAL) if the architecture is implemented correctly. It need not touch the application code at all. For example, this is how most modern web frameworks are built.

There are a number of other aspects which are related to the business context of a system, into which architecture provides valuable insights. However, since this is a book mostly on the technical aspects of software architecture, we have limited our discussion to the ones given in the preceding table.

Now, let us take on the second question:

Why not build a system without a formal software architecture?

If you've been following the arguments so far thoroughly, it is not very difficult to see the answer for it. It can, however, be summarized in the following few statements:

Every system has an architecture, whether it is documented or notDocumenting an architecture makes it formal, allowing it to be shared among stakeholders, making change management and iterative development possibleAll the other benefits and characteristics of software architecture are ready to be taken advantage of when you have a formal architecture defined and documentedYou may be still able to work and build a functional system without a formal architecture, but it would not produce a system which is extensible and modifiable, and would most likely produce a system with a set of quality attributes quite far away from the original requirements

System versus enterprise architecture

You may have heard the term architect used in a few contexts. The following job roles or titles are pretty common in the software industry for architects:

The Technical architectThe Security architectThe Information architectThe Infrastructure architect

You also may have heard the term System architect, perhaps the term Enterprise architect, and maybe, Solution architect also. The interesting question is: What do these people do?

Let us try and find the answer to this question.

An Enterprise architect looks at the overall business and organizational strategies for an organization, and applies architecture principles and practices to guide the organization through the business, information, process, and technology changes necessary to execute their strategies. The Enterprise architect usually has a higher strategy focus and a lower technology focus. The other architect roles take care of their own subsystems and processes. For example:

The Technical architect: The Technical architect is concerned with the core technology (hardware/software/network) used in an organization. A Security architect creates or tunes the security strategy used in applications to fit the organization's information security goals. An Information architect comes up with architectural solutions to make information available to/from applications in a way that facilitates the organization's business goals.

These specific architectural roles are all concerned with their own systems and subsystems. So, each of these roles is a System architect role.

These architects help the Enterprise architect to understand the smaller picture of each of the business domain they are responsible for, which helps the Enterprise architect to get information that will aid him in formulating business and organizational strategies.

The System architect: A System architect usually has a higher technology focus and a lower strategy focus. It is a practice in some service-oriented software organizations to have a Solution architect, who combines the different systems to create a solution for a specific client. In such cases, the different architect roles are often combined into one, depending on the size of the organization, and the specific time and cost requirements of the project.The Solution architect: A Solution architect typically straddles the middle position when it comes to strategy versus technology focus and organizational versus project scope.

The following schematic diagram depicts the different layers in an organization–Technology, Application, Data, People, Process, and Business, and makes the focus area of the architect roles very clear:

Enterprise versus System architects

Let's discuss the preceding diagram a bit to understand the picture it lays out.

The System architect is pictured on the bottom-left side of the diagram, looking at the system components of the enterprise. His/her focus is on the applications that power the enterprise, their data, and the hardware and software stack powering the applications.

The Enterprise architect, on the other hand, is pictured on the top, having a top-down view of the enterprise including the business goals and the people, and not just the underlying systems that power the organization. The vertical stack of business processes connect the technical components that power the organization with its people and business components. These processes are defined by the Enterprise architect in discussion with the other stakeholders.

Now that you have understood the picture behind Enterprise and System architecture, let us take a look at some formal definitions:

"Enterprise Architecture is a conceptual blueprint that defines the structure and behavior of an organization. It determines how the organization's structure, processes, personnel and flow of information is aligned to its core goals to efficiently achieve its current and future objectives."

"A system architecture is the fundamental organization of a system, represented by its structural and behavioral views. The structure is determined by the components of the system and the behavior by the relationships between them and their interaction with external systems."

An Enterprise architect is concerned with how the different elements in an organization and their interplay is tuned towards achieving the goals of the organization in an efficient manner. In this work, he/she needs the support of not just the technical architects in the organization, but also people managing the organization, such as project managers and human resource professionals.

A Systems architect, on the other hand, is worried about how the core system architecture maps to the software and hardware architecture, and the various details of human interactions with the components in the system. His/her concern never arises above the boundaries defined by the system and its interactions.

The following diagram depicts the different focus areas and scopes of the different architect roles that we've discussed so far:

Scope and focus of various architect roles in a software organization