SEN2022 · Week 12 · Physical Architecture Layer Design

Physical architecture layer design: client-server, cloud, nonfunctional requirements

Distributing the four components of an application (data storage, data access, business logic, presentation) onto hardware: server-based, client-based, 2/3/n-tier client-server, cloud (IaaS/PaaS/SaaS); moving from nonfunctional requirements to architecture and the hardware/software specification.

physical architecture layerdata storagedata access logicapplication logicpresentation logicserver-based architectureclient-based architectureclient-server architecturethin clientthick (fat) clienttwo-tierthree-tiern-tiermiddlewarescalabilitycloud computingIaaSPaaSSaaSvirtualizationavailabilitydeployment diagramnodeartifacthardware and software specification

Analysis is finished and the models are balanced. The first big decision in design: on which machines will this software run, and how will its parts be distributed? The physical architecture layer answers this question. What determines the decision is the nonfunctional requirements you gathered in week 5: performance, security, the operational environment, cultural and political constraints. The exam brings a comparison of architecture types, cloud models and the scenario “which architecture for these requirements”; sometimes an availability calculation.

Golden rules:

  1. Every application has four jobs: data storage, data access, business logic, presentation. The architecture is where these run.
  2. Thin client = presentation only. The business logic is on the server.
  3. Nonfunctional requirements choose the architecture, not the other way round.
  4. The availability calculation: downtime = total time × (1 − ratio). For components in series, the ratios are multiplied.

The four basic components

ComponentWhat it doesIn a food ordering app
Data storageStores the dataMenu, order, customer tables
Data access logicOperations that access the dataThe query “fetch the open orders of this restaurant”
Application logicBusiness rulesDelivery fee calculation, courier assignment
Presentation logicDisplay and inputThe menu screen, cart, buttons

Architecture types

Server-based architecture

All four components run on a central server (formerly a mainframe); the client is just a terminal that sends keystrokes and displays the screen.

  • Pro: central control, security, maintenance in one place.
  • Con: the server becomes a bottleneck, and growing it is expensive and not incremental (you have to buy a new and much bigger server).

Client-based architecture

The client does presentation, business logic and data access; the server only stores files (a file server).

  • Pro: simple, easy to develop.
  • Con: all the data is carried over the network to the client, so the network load is large; performance drops with many users.

Client-server architecture

The work is split: the client is responsible for presentation and the server for the data; the business logic is distributed to the two or to separate servers.

Two-tier
[Client: presentation + app logic]
          |
[DB server: data access + storage]

Three-tier
[Client: presentation]
          |
[App/web server: application logic]
          |
[DB server: data access + storage]

N-tier
[Client] - [Web srv] - [Order svc]
                     - [Payment svc]
                     - [DB server]
AdvantageDisadvantage
Client-server in generalScalable (add servers), different platforms work together, business logic can be centralizedComplex; software and updates for several tiers; middleware is needed
Two-tierSimpleBusiness logic on the client → updates are hard, fat client
Three-tier / n-tierThe load is balanced, each tier grows separately, a thin client is possibleNetwork traffic and design complexity increase

Middleware is intermediary software that lets software on different tiers talk to each other (message queues, API gateways).

Thin vs thick client: A thin client does only presentation (a web browser). A thick (fat) client also runs part of the business logic (some desktop or mobile applications). A thin client is easy to maintain; a thick client can work offline and reduces the server load.

Comparison

CriterionServer-basedClient-basedClient-server
Infrastructure costVery highMediumLow-medium
Development costMediumLowHigh
Ease of developmentLowHighLow-medium
Interface richnessLowHighHigh
Control and securityHighLowMedium
ScalabilityLowMediumHigh

Cloud computing

Hardware and software resources are rented over the internet on a pay-as-you-go model. At its basis is virtualization: one physical server runs several virtual machines.

ModelThe provider givesYou manageExample use
IaaSVirtual machine, storage, networkOperating system, runtime, application, dataRenting a VM without setting up your own server
PaaSIaaS + operating system, runtime, database serviceApplication code and dataUpload your code and let the platform run it
SaaSThe whole ready-made applicationOnly usage and settingsWeb-based e-mail, office software

Pros: low initial investment, fast growth (elasticity), maintenance is with the provider. Cons: dependence on the provider (vendor lock-in), where the data sits (legal compliance), cost in the long run, dependence on an internet connection.

Other concepts: ubiquitous computing / Internet of Things (sensors, turnstiles and smart devices connect to the system), green IT (energy efficiency, fewer physical servers with virtualization).

From nonfunctional requirements to architecture

CategorySub-requirementsEffect on the architecture
OperationalTechnical environment, system integration, portability, maintainabilityWhich platforms, which external systems to connect to; a thin client makes maintenance easier
PerformanceSpeed, capacity, availability and reliabilityNumber of servers, load balancing, backup, cloud elasticity
SecurityValue of the system, access control, encryption and authentication, virus controlPut the database in a separate protected tier, HTTPS, firewall
Cultural and politicalMultilingualism, customization, unwritten norms, legal requirementsData storage region (the Turkish data protection law, KVKK), multilingual interface, local currency

Availability calculation

Availability is the proportion of time the system is usable. A year is 365 × 24 = 8,760 hours.

allowed downtime=8760×(1−A)\text{allowed downtime} = 8760 \times (1 - A)

A        Annual downtime
99%      87.6 hours
99.5%    43.8 hours
99.9%    8.76 hours  (525.6 min)
99.99%   52.56 min

Components in series: If the web server (99%) and the database (99.5%) must work together:

A=0.99×0.995=0.98505≈98.5%A = 0.99 \times 0.995 = 0.98505 \approx 98.5\%

The total is lower than even the weakest link. The solution: redundant servers, a load balancer.

Capacity estimation

In the campus food app, 2,000 active users at lunch break, about 5 requests per minute per person:

2,000 x 5 = 10,000 requests/min
10,000 / 60 ≈ 166.67 requests/s

The server is chosen according to this peak value and a safety margin.

Worked example: the architecture decision for FitHub

Requirements:

  • O1. Members access it through a mobile app and the web; turnstiles (IoT) do check-in. (operational)
  • P1. 1,500 concurrent users across 5 branches between 18:00 and 21:00. (performance)
  • P2. 99.9% availability; if the turnstile does not work, a member cannot get in. (performance)
  • S1. Card data will not be stored; payment is with an external provider. (security)
  • C1. Personal data will be stored in Turkey or in a region compliant with the Turkish data protection law (KVKK). (cultural and political)

Decision: Three-tier (n-tier) client-server, on PaaS.

RequirementDesign that meets it
O1Thin client: a web browser and a lightweight mobile app; turnstiles connect to the application tier through a REST API
P1, P2Several servers and a load balancer in the application tier; the database is redundant
P2 (turnstile)A short offline mode at the turnstile: checking against the last synchronized member list
S1Payment is redirected to the external provider (EIF), the system stores only the transaction number
C1The cloud region is chosen appropriately; the database tier is reachable only from the application servers

Deployment diagram

+------------------+     +-------------------+
| <<device>>       |     | <<device>>        |
| Member phone     |     | Turnstile (IoT)   |
| [fithub.apk]     |     | [gate-agent]      |
+--------+---------+     +---------+---------+
         | HTTPS                   | HTTPS
         v                         v
+--------------------------------------------+
| <<execution env>> PaaS app tier (x3)       |
| [fithub-api.jar]                           |
+--------------------+-----------------------+
                     | TCP (private network)
+--------------------v-----------------------+
| <<node>> Managed DB (primary + replica)    |
+--------------------------------------------+

A node (a cube; here a box) is hardware or an execution environment, the things in square brackets are artifacts, and the arrows are communication paths.

Hardware and software specification

One of the outputs of design is a list of the resources to be bought or rented:

ItemMinimumRecommended
Application server2 virtual CPUs, 4 GB RAM3 instances, 4 virtual CPUs, 8 GB RAM, autoscaling
DatabaseManaged relational database, 50 GBPrimary + replica, daily backup
ClientCurrent browser / Android 10+, iOS 15+
NetworkHTTPS, 50 Mbps at the branchesA backup mobile line at the branches
SoftwareOperating system, runtime, database licensesA monitoring and logging tool

The specification is sent to vendors; the offers are compared on price, performance, support and reliability. The whole cost is taken into account: license, installation, training, maintenance (total cost of ownership).

Common mistakes

Wrong ideaThe truth
A thin client runs the business logicA thin client does only presentation
Two-tier = client + server, with the logic on the serverIn two-tier the business logic is usually on the client (fat client)
In SaaS you manage the operating systemThat is IaaS; in SaaS you only use the application
Cloud is always cheaperThe initial investment is low, it varies in the long run; there is a dependency risk
99.9% = 8.76 minutes of downtime a year8.76 hours
For components in series, the availabilities are averagedThey are multiplied
Choose the architecture first and invent requirements laterNonfunctional requirements determine the architecture
Drawing classes in a deployment diagramNodes, artifacts and connections are drawn

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

Name the four basic functions of any application that the architecture distributes between client and server.

Show answer
Data storage, data access logic, application (business) logic, presentation logic

Data storage: storing the data. Data access logic: the operations that access the data (SQL queries). Application logic: business rules. Presentation logic: displaying to the user and taking input. The type of architecture is determined by where these four run.

Question 2medium

In a three-tier architecture, where does each part typically run?

Show answer
Presentation on the client; application logic on an application (web) server; data access logic and data storage on a database server.

In two-tier, the client holds presentation + business logic and the server holds the data. In three-tier, the business logic moves to a separate application server. In n-tier the business logic is split across several servers (e.g. a web server + a payment service + a notification service).

Question 3easy

Which statement about thin and thick clients is TRUE?

  1. A thin client runs most of the application logic
  2. A thick client runs only presentation logic
  3. A thin client (e.g., a web browser) runs little or no application logic
  4. Thin clients cannot use servers
Show answer
C) A thin client (e.g., a web browser) runs little or no application logic

A thin client does only (or mostly) presentation, and the business logic is on the server. A thick (fat) client also runs most of the business logic. A thin client is easy to maintain: updates are made on the server.

Question 4medium

Which architecture's main advantage is scalability, because servers can be added at each tier?

  1. Server-based (mainframe)
  2. Client-based
  3. Client-server (n-tier)
  4. Stand-alone desktop
Show answer
C) Client-server (n-tier)

In client-server, when load grows, servers are added or strengthened (scale up / scale out). In a server-based architecture the single central server is a bottleneck and growing it is expensive. In a client-based architecture network traffic grows.

Question 5medium

A startup uses a provider's database, runtime and OS, and only deploys its own code. Which cloud model is this?

  1. IaaS
  2. PaaS
  3. SaaS
  4. On-premises
Show answer
B) PaaS

IaaS: virtual machines, storage, network; the operating system and everything above is yours. PaaS: the platform (runtime, database service) is provided, and you put your code on it. SaaS: you use a ready-made application (e-mail, CRM).

Question 6medium

A system must have 99.9% availability. What is the maximum downtime per year (365 days)?

Show answer
8.76 hours

A year has 365 × 24 = 8,760 hours. The downtime share is 0.1%: 8,760 × 0.001 = 8.76 hours (about 525.6 minutes).

Question 7medium

Same question for 99.99% availability, in minutes per year.

Show answer
52.56 minutes

8,760 × 60 = 525,600 minutes. 0.01% of it: 525,600 × 0.0001 = 52.56 minutes. Each extra "9" cuts the downtime to one tenth and raises the cost considerably.

Question 8hard

A web server with 99% availability and a database server with 99.5% availability are both required (in series). What is the overall availability?

Show answer
≈ 98.5%

With components in series both must work, so the probabilities are multiplied: 0.99 × 0.995 = 0.98505 ≈ 98.5%. The total availability is lower than even the weakest component. That is why critical components are made redundant.

Question 9easy

At peak time 2,000 users each send about 5 requests per minute. How many requests per second must the server handle?

Show answer
≈ 167 requests per second

2,000 × 5 = 10,000 requests/minute. 10,000 / 60 = 166.67 ≈ 167 requests/second. In capacity planning a safety margin is added on top.

Question 10hard

Classify: 'The app must be available in Turkish and English and follow KVKK rules.' Which nonfunctional category drives this, and what is one architecture consequence?

Show answer
Cultural and political; e.g., store personal data in a region/data center that complies with KVKK and design the UI for multiple languages.

Language support and legal compliance are cultural and political requirements. The effect on the architecture: in which country/region the data will be stored (choice of cloud region), multilingual interface support, an access log for personal data.

Question 11easy

In a UML deployment diagram, what does a 3D box represent?

  1. A class
  2. A node (hardware or execution environment)
  3. A use case
  4. An artifact only
Show answer
B) A node (hardware or execution environment)

In a deployment diagram, a node (a cube) is hardware or an execution environment (a server, a phone, a Docker container). An artifact (a software file: .jar, .apk) is placed inside a node. The line between nodes is a communication path (HTTPS, TCP).

Verification: Availability downtimes, the total availability of components in series, and requests per second were computed with node (verify/SEN2022/12.mjs). Conceptual questions were compared with the standard definitions of architecture types, cloud service models and nonfunctional requirement categories.

Review card

4 components: data storage, data access logic, application logic, presentation logic Server-based: everything on the server (terminal); centralized, expensive to grow Client-based: logic on the client, the server only holds files; high network load Client-server: 2-tier (client: presentation+logic), 3-tier (separate application server), n-tier Thin client: presentation only (browser); thick client: logic on the client too C/S pro: scalable, platform independent; con: complex, updates are hard Cloud: IaaS (virtual machine) / PaaS (platform) / SaaS (ready-made application) Nonfunctional → architecture: operational, performance, security, cultural & political Availability: downtime = 8760 hours × (1 - ratio) 99% → 87.6 h 99.9% → 8.76 h 99.99% → 52.56 min Components in series: availabilities are multiplied Deployment diagram: node (cube), artifact, communication path Spec: hardware + software + network, minimum and recommended values