Web Applications Software Engineering 2017 Alessio Gambi - Saarland - - PowerPoint PPT Presentation

web applications
SMART_READER_LITE
LIVE PREVIEW

Web Applications Software Engineering 2017 Alessio Gambi - Saarland - - PowerPoint PPT Presentation

Web Applications Software Engineering 2017 Alessio Gambi - Saarland University Based on the work of Cesare Pautasso, Christoph Dorn, Andrea Arcuri, and others ReCap Software Architecture A software systems architecture is the set of


slide-1
SLIDE 1

Web Applications

Software Engineering 2017 Alessio Gambi - Saarland University

Based on the work of Cesare Pautasso, Christoph Dorn, Andrea Arcuri, and others

slide-2
SLIDE 2

ReCap

slide-3
SLIDE 3

Software Architecture

A software system’s architecture is the set of principal design decisions made about the system.

  • N. Taylor et al.

Abstraction Communication Visualization and Representation Quality Attributes

slide-4
SLIDE 4

Every system a software architecture has What designers want

slide-5
SLIDE 5

Design

  • Architectural Styles
  • Architectural Patterns
  • Building Blocks
  • Software Components
  • Component API/Interfaces
  • Software Connectors
slide-6
SLIDE 6

Send HTTP request, and get HTTP response containing the HTML page Browser visualizes it

Send a HTTP request, and get back a HTML page which will be visualized in the

slide-7
SLIDE 7

Client/Server

  • Many clients, active, close to users
  • One server, passive, close to data
  • Single point of failure, scalability
  • Security, scalability
slide-8
SLIDE 8

HTTP

The Hypertext Transfer Protocol

slide-9
SLIDE 9

HTTP

The Hypertext Transfer Protocol

Connector or Component ?

slide-10
SLIDE 10

HTTP

The Hypertext Transfer Protocol

Connector or Component ? Synch or Asynch ?

slide-11
SLIDE 11

HTTP

The Hypertext Transfer Protocol

Connector or Component ? Synch or Asynch ? Stateful or stateless ?

slide-12
SLIDE 12

HTTP Request

  • Action: verb, express the intent
  • Headers: meta-data
  • Body: optional, can be anything, a stream of

bytes, form data, session information, etc.

slide-13
SLIDE 13

HTTP Actions

Have precise semantic, and a web application might not implement all of them Web applications must to implement the semantic right

GET retrieve a resource POST send data and/or create a resource PUT replace an existing resource DELETE delete a resource HEAD retrieve HEADers but not body OPTIONS check the methods available on the resource

slide-14
SLIDE 14

HTTP Response

Headers and status Status codes, organized in families:

1xx: information 2xx: success 3xx: redirection 4xx: user error 5xx: server error

Delivers a resource: a page HTML, a CSS file for the style, images, JS libraries, etc.

slide-15
SLIDE 15

HTTP Body

  • Transfer the main part of the data, but not the only

way to send data
 query params, custom headers

  • Required in POST and PUT requests
  • Required in responses to GET requests
  • HEAD must not provide one
slide-16
SLIDE 16

HTML

The Hypertext Markup Language

slide-17
SLIDE 17

es

T ts

Resources

One request per resources, multiple requests in parallel All requests must complete before a page is fully displayed

slide-18
SLIDE 18

Static vs Dynamic Pages

Static:

Files are served as they are (index.html) content does not change

slide-19
SLIDE 19

Static vs Dynamic Pages

Static:

Files are served as they are (index.html) content does not change

Dynamic:

The HTML (or part of it) is generated upon request based on data

slide-20
SLIDE 20

State-Logic-Display

cluster elements that change at the same rate

slide-21
SLIDE 21

Server-Side HTML Rendering

  • The HTML page is created on the server and sent

back to the client

  • Overhead in processing each request if the page is

created from scratch

  • Same content for different displays


Desktop vs Tablet vs Mobile

slide-22
SLIDE 22

Presenter-View

extract the content from the model to be presented from the rendering into screens/web pages

slide-23
SLIDE 23

Server-Side HTML Rendering

  • Based on HTML templates that mix together HTML

tags, data, and code

http://www.embeddedjs.com/getting_started.html

slide-24
SLIDE 24

Server-Side HTML Rendering

  • Based on HTML templates that mix together HTML

tags, data, and code

  • Different technologies:


PHP scripts — index.php


JavaServer Faces (JSF) — index.xhtml
 Embedded Ruby (ERB) — index.html.erb

slide-25
SLIDE 25
slide-26
SLIDE 26

Server-Side HTML Rendering

  • Based on HTML templates that mix together HTML

tags, data, and code

  • Different technologies:


PHP scripts — index.php


JavaServer Faces (JSF) — index.xhtml
 Embedded Ruby (ERB) — index.html.erb

  • Templates do not necessarily target the entire page

and they might not be stored in “files”

slide-27
SLIDE 27

Components

slide-28
SLIDE 28

Content Management Systems
 (CMS)

slide-29
SLIDE 29
slide-30
SLIDE 30

Design

slide-31
SLIDE 31

3-Tier Architecture

Web Browser Front End App Server Back End

Business logic Presentation Data source

slide-32
SLIDE 32

Layered (Style)

  • Communications 1 layer up/down
  • Information hiding, no circular deps
  • Possibly bad performance
  • Good evolvability
slide-33
SLIDE 33

What run where?

thin-client fat-client

slide-34
SLIDE 34

3-Tier Architecture

Web Browser Front End App Server Back End

Business logic Presentation Data source

slide-35
SLIDE 35

Data Layer

Back End

  • Persistence
  • Storage
slide-36
SLIDE 36

A Mapping Problem

Domain model Data storage

slide-37
SLIDE 37

Domain Model

  • Represent concepts in the domain and their

relations, not as rows in a database

  • Network of interconnected concepts
  • Abstract Data Type


data and the behavior

slide-38
SLIDE 38

Storage model

How to store data?

  • Key-Value Model


list of keys and values (hashtable style)

  • Relational Model


traditional SQL model

  • Document-oriented Model


schema-less documents

  • Graph-oriented Model


data is stored as an interconnected graph

slide-39
SLIDE 39

Key-Value

  • Implement a map
  • Values have no schema
slide-40
SLIDE 40

Relational

  • Set-theory
  • Collection of tables with

rows and columns

slide-41
SLIDE 41

Document-oriented

  • Data stored in

document but not relations

  • Extends Key-Value
slide-42
SLIDE 42

Graph-oriented

  • Data stored as network

graph

  • Relations first-class

citizens

slide-43
SLIDE 43

Polyglot Persistence

Multiple ways to store data

User Sessions Financial Data Shopping Cart Recomme ndation Product Catalog Reporting Relational Document KeyValue Graph

slide-44
SLIDE 44

3-Tier Architecture

Web Browser Front End App Server Back End

Business logic Presentation Data source

slide-45
SLIDE 45

Application Layer

App Server

  • Data access, navigation, and persistence
  • Data processing (Business logic)
slide-46
SLIDE 46

Plugin

  • Explicit extension points
  • Static/Dynamic composition
  • Low security (3rd party code)
  • Extensibility and customizability
slide-47
SLIDE 47

A Different Problem (?)

Programming Language Storage Architecture

slide-48
SLIDE 48

Data Access API

Relational Database (e.g. MySQL) REST API REST API Object-based storage (e.g. S3) Document- based Database Relational Database Service API Tool-specific API

  • Add an abstraction layer that

the represent the database in the application

  • Wrap the communication with

the data store and expose it as domain model

slide-49
SLIDE 49

Data Source Patterns

  • Row Data Gateway


One instance per row returned by a query

  • Table Data Gateway


One instance per table

  • Active Record


Encapsulates DB access and adds business logic to data

  • Data Mapper


loads DB into Domain Model, and vice-versa

slide-50
SLIDE 50

Row and Table Gateways

  • Based on table structure
  • Conversion of object type to database format
  • Typically stateless
  • Push back and forth data
slide-51
SLIDE 51

Active Record

static get(int id) insert update delete calculateRecognitions() productId productName Product

Data Store

Row Data Gateway + Business Logic

  • Methods for:
  • Create instances from SLQ results
  • Insert new instances in the data store
  • Update data store based on instances data
  • Find relevant instances
slide-52
SLIDE 52

Data Mapper

calculateRecognitions() productId productName Product

Data Store

get(int id) insert update delete ProductMapper

  • Decouple objects structure from database structure
  • There may be more than one mapper per domain
  • bject
slide-53
SLIDE 53

Navigate (Relational) Data

Traverse object graph Join over foreign keys

slide-54
SLIDE 54

Lazy Loading

slide-55
SLIDE 55

Lazy Loading

Interrupt the load at some point and resume it later

  • nly if needed
slide-56
SLIDE 56

Lazy Loading Patterns

  • Lazy Initialization


Checks if field is null at every access

  • Value Holder


Wraps lazy-loaded objects

  • Virtual Proxy


Mocks field access and loads values on the demand

  • Ghost


Real object but partially loaded, missing data loaded on


first access

slide-57
SLIDE 57

3-Tier Architecture

Web Browser Front End App Server Back End

Business logic Presentation Data source

slide-58
SLIDE 58

Front End

Front End

  • Generate the HTML based on request and data

from the backend

  • Can handle client side interactions both inside the

server and the client’s browser

  • Security, input validation, responsiveness, etc.
slide-59
SLIDE 59

Web Frameworks

slide-60
SLIDE 60

Plugin

  • Explicit extension points
  • Static/Dynamic composition
  • Low security (3rd party code)
  • Extensibility and customizability
slide-61
SLIDE 61

Client Side

slide-62
SLIDE 62

JavaScript

  • a programming language executed in the browser


nothing to do with java

  • JS files/libraries referenced by the web page


like any other resource

  • Can be inlined
  • Dynamically manipulates the page Document

Object Model (DOM) to alter page’s content, structure, and behavior

slide-63
SLIDE 63

AJAX

Asynchronous JavaScript and XML

slide-64
SLIDE 64

JS not so (well designed) easy

slide-65
SLIDE 65

JS Frameworks

slide-66
SLIDE 66

Case Study

slide-67
SLIDE 67

Main Scenarios

  • A user requests an article during normal operation

and gets the rendered article HTML page.


  • An editor saves an edited article during normal
  • peration and the article is saved.
slide-68
SLIDE 68
slide-69
SLIDE 69
slide-70
SLIDE 70

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources

slide-71
SLIDE 71

Qualities

  • “Basic” implementation
  • Limited scalability
  • Single point of failure
  • Limited Security
slide-72
SLIDE 72

Performance Tactics

  • Control Resource Demand
  • Increase the resource efficiency (caching)
  • Reduce overhead (pre-generate HTML from PHP)
  • Manage Resources
  • Schedule resources (load balancer)

https://www.digitalocean.com/community/tutorials/5-common-server-setups-for-your-web-application

slide-73
SLIDE 73

Load Balancing

deploy many replicated instances of the server

  • n multiple machines
slide-74
SLIDE 74
slide-75
SLIDE 75
slide-76
SLIDE 76

Caching + Load Balancing

FrontEnd (Apache)

slide-77
SLIDE 77

Caching + Load Balancing

Squid (Caching) Apache

slide-78
SLIDE 78
slide-79
SLIDE 79

Caching + Load Balancing

Squid (Caching) Apache

slide-80
SLIDE 80

Caching + Load Balancing

Squid Apache LoadBalancer (Squid) LoadBalancer

slide-81
SLIDE 81

Caching + Load Balancing

Squid Apache LoadBalancer (Squid) LoadBalancer Squid Apache LoadBalancer LoadBalancer Squid Squid Apache Apache

slide-82
SLIDE 82

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources

slide-83
SLIDE 83

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Cache Cache

slide-84
SLIDE 84

Performance Tactics

  • Control Resource Demand
  • Prioritize events (deferred article updates)
  • Manage Resources
  • Introduce concurrency (distributed database)
  • Schedule resources (load balancer)
  • Multiple copies of data and computations

https://www.digitalocean.com/community/tutorials/5-common-server-setups-for-your-web-application

slide-85
SLIDE 85

Master/Slave

split a large job into smaller independent partitions which can be processed in parallel

slide-86
SLIDE 86

Distribution + Replication

Database

More reads than writes Near-live updates (no strict consistency requirements)

slide-87
SLIDE 87

Distribution + Replication

DB Slave Load Balancer Reads Writes DB Master

More reads than writes Near-live updates (no strict consistency requirements)

slide-88
SLIDE 88

Clear data separation (Article Name: A-B, C-D, etc..)

Distribution + Replication

Data Sharding

slide-89
SLIDE 89

Distribution + Replication

DB Slave Load Balancer Reads Writes DB Master

slide-90
SLIDE 90

Distribution + Replication

DB Slave Load Balancer (Master) Reads Writes DB Master (Shard) Partition Logic (Sharding, Relication

slide-91
SLIDE 91

Visualization

slide-92
SLIDE 92

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Cache Cache

slide-93
SLIDE 93

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Parser Cache Static Resources Loader Cached Cached Cached Job Runner Writes Job Queue HTML File Cache Precompile/Recompile Regenerate/Invalidate

slide-94
SLIDE 94

Security/Availability Tactics

  • Prevent Attacks
  • Challenge Tokens (CSRF)
  • Validation (User) and Sanitization (SQL Injection, XSS)
  • Resist Attacks
  • Maintain multiple copies of computations
  • Maintain multiple copies of data
  • Recover from Attacks
  • DB Versioning (Recovery from data loss)
slide-95
SLIDE 95

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Cache Cache

slide-96
SLIDE 96

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Cache Cache Sanitizer Pipeline User Access

slide-97
SLIDE 97

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Sanitizer Cache Cache

slide-98
SLIDE 98

Additional Qualities

slide-99
SLIDE 99

Extensibility

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Sanitizer Cache Cache

slide-100
SLIDE 100

Extensibility

Backend Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Sanitizer Cache Cache Hook Engine Register Callback Notify Notify Notify Notify Notify External Module

slide-101
SLIDE 101

Configurability/Customizability

Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Sanitizer Cache Cache

slide-102
SLIDE 102

Global Variables and Configurations Parser ArticleEdit Reads Writes ArticleView Submit Logic UI Page Skinning Localization Static Resources Loader Cache Cache Sanitizer Cache Cache

Configurability/Customizability

slide-103
SLIDE 103

Process View

slide-104
SLIDE 104

Read Article

A user requests an article during normal

  • peration and gets the rendered article

HTML page.

slide-105
SLIDE 105

GET Article HTML Cache LoadBalancer Select DB Article Exists Parser Cache Get Article from DB Parse Content Render Content Missing Page

Y Y Y N

N

Read Article

slide-106
SLIDE 106

Write/Edit Article

An editor saves an edited article during normal operation and the article is saved.

slide-107
SLIDE 107

Submit Logic User Authorized LoadBalancer Select DB Article Edit Write Conflict Error Page Create Edit Form Render Content

Y Y

Update Job

Write/Edit Article

slide-108
SLIDE 108

Summary

  • Work incrementally
  • Use different architectural views
  • Start the design from the domain model and go up

in the layers

  • Use frameworks whenever possible
  • Each design decision has a rationale (hoisting)