Quantum Software Architecture Design Course

Written by: Igor Korotach

Section 3

Architectural Styles & Patterns

Small recap

Cross-cutting concern

In aspect-oriented software development, cross-cutting concerns are aspects of a program that affect several modules, without the possibility of being encapsulated in any of them. These concerns often cannot be cleanly decomposed from the rest of the system in both the design and implementation

Popular cross-cutting concerns

  • Logging 
  • Authentication & Authorization
  • Communication
  • Caching
  • Error handling
  • Synchronization 
  • Data validation
  • Memory Management

General approaches

Centralized vs Decentralized architecture

Layers vs Tier

Client - Server vs P2P

Centalized architecture

Some of the most important characteristics of centralized applications are:

1. Global clock

2. Single code base

3. Single point of response

Pros

  • Easier deployment
  • More straightforward security 
  • Easier development in general cases

Cons

  • Worse scalability
  • More difficult resource utilization
  • Single point of fault
  • Difficult to maintain 

Pros & Cons of Centralized Architecture

Decentalized architecture

Some of the most important characteristics of decentralized applications are:

1. Independent clock

2. Fault-tolerance 

3. Multiple points of response

Pros

  • Better resource control
  • Fault-tolerance (in principle)
  • Easier scaling
  • More flexible maintenance (canary/blue green deployments allowed)

Cons

  • More difficult security patterns
  • Duplication of cross-cutting concerns
  • Requires DevOps pipelines to be maintained efficiently

Pros & Cons of Decentralized Architecture

Layered architecture

Layered architecture is an architectural style where the application is structured into independent layers which have their own independent level of responsibility and data control

Things to watch out for in layered architecture design

  • Dependency Injection is king
  • As quoted by Joel Spolsky "All non-trivial abstractions, to some degree, are leaky"
  • Business logic layer should live in its own layer
  • If you have a low-level/performance critical application, please don't use layers. Opt for single module procedural programming instead

DI Python

Non-DI Python

class Database:
    def __init__(self, connection):
        self.connection = connection


class Service:
    def __init__(self, database: Database):
        self.database = database


class Controller:
    def __init__(self, service: Service):
        self.service = service


def main():
    database = Database('connection')
    service = Service(database)
    controller = Controller(service)
    controller.run()
class DatabaseSingleton:
    _instance = None

    def __init__(self):
        self._instance = DatabaseSingleton()

# Some other file
service = None

class Service:
    def __init__(self):
        service = Service()


class Controller:
    def __init__(self):
        import service
        if not service:
            service = Service()


def main():
    controller = Controller()
    controller.run()

N-Tier architecture

N-Tier also known as N-Level architecture is an architecture style that focuses on physical separation of structural units.

Layers - logical separations, e.g. business logic vs data querying

Levels - physical/network separation, e.g. Frontend/Backend

Things to watch out for in N-Tier architecture design

  • Though 3 level architecture is usually brought up (Frontend/Backend/Database), usually there are more in real applications
  • Don't forget about load-balancing, reverse proxy and caching tiers
  • Don't overuse tier system, each tier adds to duplication of cross-cuting concerns 
  • Tiers bring their inherent overhead of network calls, don't forget it

MVC (Model-View-Controller) Architecture

MVC (Model-View-Controller)

MVC relies on direct flow of data across the layers, all the initiated actions are explicit.

E.g. Receive request to click a button in controller, propagate to model, change state, render new state in the view

 

Is usually used in Backend applications for direct flow

MVVM (Model-View-ViewModel)

MVVM heavily relies on data-binding, i.e. implicit connection between UI and business logic.

E.g. create an interactive button, that handles click as on-click and updates state automatically

 

Is usually used in GUI applications for easier interactions

Client - Server vs Peer to Peer (P2P) Architecture

Client - Server architecture

Pros

  • Better observability
  • Centralized management
  • Better security

Cons

  • Difficult scaling
  • Dependence on the server
  • Cost of maintenance
  • Design complexity

Pros & Cons of Server - Client architecture

Peer to Peer (P2P) architecture

Pros

  • Scaling is provided
  • Minimal infrastructure costs
  • Fault-tolerance

Cons

  • Resource discovery is a non-trivial task
  • Debugging & error recovery
  • Difficult protocol upgrading & control
  • Extremely difficult to implement correct security patterns

Pros & Cons of P2P architecture

Next time. Advanced Architectural Patterns. SOA, EDA, Hexagonal, etc.

Thanks for your attention. You've been awesome!

Questions?

  • Presentation link: https://slides.com/emulebest/architecture-3

Quantum Architecture Course - 3

By Igor Korotach

Quantum Architecture Course - 3

  • 106