Glue Stack
GitHubLive AppChat
1.0.0
1.0.0
  • Read Me
  • Architecture
    • How Web Applications Work
  • Development
    • Our Development Process
    • Running Locally
    • Setup Development Tools
    • Setup Visual Studio Code (vscode)
    • Setup Database Connection In Sequel Pro
    • Building Glue Stack From an Empty Folder
    • Developing Process Documentation
    • UI Connect Component
  • Infrastructure
    • Setup AWS Account
    • Setup AWS Cloud Infrastructure
    • Continuous Integration (CI): Travis CI
    • Performance Testing and Connection Pool Sizes
Powered by GitBook
On this page
  • DNS
  • Static Web Pages
  • Dynamic Web Pages
  • Single Page Applications
  • 3-Tier Architecture
  1. Architecture

How Web Applications Work

PreviousArchitectureNextDevelopment

Last updated 6 years ago

I use markdown for sequence diagrams and include the ascii version using this because gitbooks doesn't support it yet.

You can also parse the markdown using something like which is included in my current markdown editor, .

DNS

This is a web application so lets start from the internet browser (think of Google Chrome or Safari). What happens when you go to ?

Browser->DNS: What is the IP address for google.com?
DNS->Browser: The IP of google.com is 216.58.199.46
+---------+                                   +-----+
| Browser |                                   | DNS |
+---------+                                   +-----+
     |                                           |
     | What is the IP address for google.com?    |
     |------------------------------------------>|
     |                                           |
     |     The IP of google.com is 216.58.199.46 |
     |<------------------------------------------|
     |                                           |

How DNS (Domain Name System) works is out of the scope of this article but this article is pretty good; . tl;dr domains are resolved by your local computer and a chain of remote DNS servers.

You can find out the ip address of a domain from your terminal.

dig google.com

Static Web Pages

Browser->216.58.199.46: GET / HTTP/1.1
216.58.199.46->Browser: Here is the html page for /
+---------+                        +-------------+
| Browser |                        | IP_Address  |
+---------+                        +-------------+
     |                                    |
     | GET / HTTP/1.1                     |
     |----------------------------------->|
     |                                    |
     |        Here is the html page for / |
     |<-----------------------------------|
     |                                    |

Traditionally, the server will return a HTML page which can instruct the browser to make further requests for other assets such as images or code to style the page. This is the case with google.com and you can see that by:

  1. Right click the page

  2. Select Inspect

  3. Select the Network tab.

  4. Refresh the page.

  5. Scroll to the top of the pane.

The first asset is the root HTML page and you can see the code by clicking on the request then selcting the response tab. From there it issues requests for the other assets like the image.

Note: we'll exclude the DNS part for the rest of this article now that we've covered it.

Dynamic Web Pages

Dynamic web pages were the next step - web pages that are generated when the request is received. It might look like this.

Browser->Server: GET / HTTP/1.1
Server->Database: get latest blog post
Database->Server: here's the latest blog post
Server->Browser: <html><h1>Blog Title!</h1></html>
+---------+                               +---------+                        +-----------+
| Browser |                               | Server  |                        | Database  |
+---------+                               +---------+                        +-----------+
     |                                         |                                   |
     | GET / HTTP/1.1                          |                                   |
     |---------------------------------------->|                                   |
     |                                         |                                   |
     |                                         | get latest blog post              |
     |                                         |---------------------------------->|
     |                                         |                                   |
     |                                         |       here's the latest blog post |
     |                                         |<----------------------------------|
     |                                         |                                   |
     |      <html><h1>Blog Title!</h1></html>  |                                   |
     |<----------------------------------------|                                   |
     |                                         |                                   |

This pattern takes more resources to produce a page than the static pattern because we're doing a lot more on each request.

Single Page Applications

An SPA could load a dynamic web page into the current page but that would mean the server would have to know what the ui is going to look like in order for it to return the correct html. We have more flexibility if the server returns structured data and the ui handles the presentation of that data. This is what we call separation of concerns.

Browser->File Server: GET / HTTP/1.1
File Server->Browser: static assets for single page application
Browser->API: GET /some-data HTTP/1.1
API->Browser: {"todaysWeather": "Sunny"}
+---------+                                      +-------------+ +-----+
| Browser |                                      | File_Server | | API |
+---------+                                      +-------------+ +-----+
     |                                                  |           |
     | GET / HTTP/1.1                                   |           |
     |------------------------------------------------->|           |
     |                                                  |           |
     |        static assets for single page application |           |
     |<-------------------------------------------------|           |
     |                                                  |           |
     | GET /some-data HTTP/1.1                          |           |
     |------------------------------------------------------------->|
     |                                                  |           |
     |                                   {"todaysWeather": "Sunny"} |
     |<-------------------------------------------------------------|
     |                                                  |           |

Single page applications can choose when to retrieve data. Is it on page load like the glue stack list page or is it on some user action like clicking the done button. It could even at a set interval like some 'realtime' sports scores websites.

Just like the dynamic web page this data might come from a database or an external source but in glue stack it is most certainly a database.

3-Tier Architecture

This is how Glue Stack works.

Browser->API: GET me some data
API->DB: data please
DB->API: here is the table of data
API->Browser: here is the data in JSON
+---------+                     +-----+                        +-----+
| Browser |                     | API |                        | DB  |
+---------+                     +-----+                        +-----+
     |                             |                              |
     | GET me some data            |                              |
     |---------------------------->|                              |
     |                             |                              |
     |                             | data please                  |
     |                             |----------------------------->|
     |                             |                              |
     |                             |    here is the table of data |
     |                             |<-----------------------------|
     |                             |                              |
     |    here is the data in JSON |                              |
     |<----------------------------|                              |
     |                             |                              |

The browser can also make changes to data using the same flow but with different HTTP methods like POST and PATCH.

Your browser will establish a connection to 216.58.199.46 and send a GET request to the "/" path of the server, GET being a type of . The server will then respond based on the request. This is important: HTTP is a request-response protocol; the request has data and the response has data based on the request.

Go to in .

If we think about the simplest example of a HTML page, all the assets are static - they don't change. They're just files that a simple server sends when the path matches the filename. We could use something like (Simple Storage Service) for this (we do).

Fun fact: I wanted to use my website for the previous section but learned about the .

This is the pattern that made popular particular with the world's largest open source blog platform . It is incredibly powerful because we could fetch some really cool data like today's weather or the latest sports scores. The data might even come from an external service so we might not even need to handle the database ourselves.

For pages that don't change that often like blogs or basic websites there are tools like and that try to create static pages before the request comes in so they have the same performance as static websites but that's a bit out of the scope of this article.

Fun fact: you can even do this pattern with React now with .

Glue stack is a (SPA) which follows on from the previous examples. It aims to provide a better user experience by loading data into the current page instead of completely reloading it. Go ahead and click the signup button on to see for yourself.

This pattern starts exactly like the static pattern, what's different is what happens next. The root html page will make requests for more static assets (not included in the diagram for simplicity) just like before, but the important asset for an SPA is a asset. Javascript is the programming language for browsers and is particularly important for making single page applications work. Just to be explicit the javascript asset is static just like the original html page.

Javascript is very powerful and among thousands of other things, can retrieve data from servers using what's called an . API is a vague term since a programming interface can mean a lot of different things. When we're talking about APIs in a web developer context we're usually talking about HTTP JSON APIs. (Some people call them APIs but that term seems to be pretty controversial so we'll just avoid it.) stands for javascript object notation so its really just a way of structuring data that's really easy for javascript applications to use. An example of JSON is in the diagram.

Further reading about this architecture is available at .

ASCII Sequence Diagram Creator
js-sequence-diagrams
Typora
google.com
DNS: Why It’s Important & How It Works
HTTP
HTTP request method
cadbox1.github.io/glue-stack
Google Chrome
AWS S3
host header
PHP
Wordpress
wordpress caches
static site generators
server side rendering
single page application
glue-stack
javascript
API
REST
JSON
Architecture