031.2 Lesson 1
Certificate: |
Web Development Essentials |
---|---|
Version: |
1.0 |
Topic: |
031 Software Development and Web Technologies |
Objective: |
031.2 Web Application Architecture |
Lesson: |
1 of 1 |
Introduction
The word application has a broad meaning in technological jargon. When the application is a traditional program, executed locally and self-sufficient in its purpose, both the application’s operating interface and the data processing components are integrated in a single “package”. A web application is different because it adopts the client/server model and its client portion is based on HTML, which is obtained from the server and, in general, rendered by a browser.
Clients and Servers
In the client/server model, part of the work is done locally on the client side and part of the work is done remotely, on the server side. Which tasks are performed by each party varies according to the purpose of the application, but in general it’s up to the client to provide an interface to the user and to layout the content in an attractive manner. It’s up to the server to run the business end of the application, processing and responding to requests made by the client. In a shopping application, for example, the client application displays an interface for the user to choose and pay for the products, but the data source and the transaction records are kept on the remote server, accessed via the network. Web applications perform this communication over the Internet, usually via the Hypertext Transfer Protocol (HTTP).
Once loaded by the browser, the client side of the application initiates interaction with the server whenever necessary or convenient. Web application servers offer an application programming interface (API) that defines the available requests and how those requests should be made. Thus, the client constructs a request in the format defined by the API and sends it to the server, which checks for any prerequisites for the request and sends back the appropriate response.
While the client, in the form of a mobile application or desktop browser, is a self-contained program with regard to the user interface and instructions for communicating with the server, the browser must obtain the HTML page and associated components—such as images, CSS, and JavaScript—that define the interface and instructions for communicating with the server.
The programming languages and platforms used by client and server are independent, but use a mutually understandable communication protocol. The server portion is almost always performed by a program without a graphical interface, running in highly available computing environments so that it is always ready to respond to requests. In contrast, the client portion runs on any device that is capable of rendering an HTML interface, such as smartphones.
In addition to being essential for certain purposes, the adoption of the client/server model allows an application to optimize several aspects of development and maintenance, since each part can be designed for its specific purpose. An application that displays maps and routes, for example, does not need to have all maps stored locally. Only maps relating to the location of the users’s interest are required, so only those maps are requested from the central server.
The developers have direct control over the server, so they can also modify the client that is provided by it. This allows developers to improve the application, to a greater or lesser extent, without the need the user to explicitly install new versions.
The Client Side
A web application should run the same way on any of the most popular browsers, as long as the browser is up to date. Some browsers may be incompatible with recent innovations, but only experimental applications use features not yet widely adopted.
Incompatibility issues were more common in the past, when different browsers had their own rendering engine and there was less cooperation in formulating and adopting standards. The rendering engine is the main component of the browser, as it is responsible for transforming HTML and other associated components into the visual and interactive elements of the interface. Some browsers, notably Internet Explorer, needed special treatment in the code so as not to break the pages expected functioning.
Today, there are minimal differences between the main browsers, and incompatibilities are rare. In fact, the Chrome and Edge browsers use the same rendering engine (called Blink). The Safari browser, and other browsers offered on the iOS App Store, use the WebKit engine. Firefox uses an engine called Gecko. These three engines account for virtually all browsers used today. Although developed separately, the three engines are open source projects and there is cooperation between their developers, which facilitates compatibility, upkeep, and the adoption of standards.
Because browser developers have taken so much effort to stay compatible, the server is not normally linked to a single type of client. In principle, an HTTP server can communicate with any client that is also capable of communicating via HTTP. In a map application, for example, the client can be a mobile application or a browser that loads the HTML interface from the server.
Varieties of Web Clients
There are mobile and desktop applications whose interface is rendered from HTML and, like browsers, can use JavaScript as a programming language. However, unlike the client loaded in the browser, the HTML and the necessary components for the native client to function are locally present since the installation of the application. In fact, an application that works this way is virtually identical to an HTML page (both are even likely to be rendered by the same engine). There are also progressive web apps (PWA), a mechanism that allows you to package web application clients for offline use—limited to functions that do not require immediate communication with the server. Regarding what the application can do, there is no difference between running the browser or packaged in a PWA, except that in the latter the developer has more control over what is stored locally.
Rendering interfaces from HTML is such a recurring activity that the engine is usually a separate software component, present in the operating system. Its presence as a separate component allows different applications to incorporate it without having to embed it in the application package. This model also delegates the maintenance of the rendering engine to the operating system, facilitating updates. It is very important to keep such a crucial component up to date in order to avoid possible failures.
Regardless of their delivery method, applications written in HTML run on an abstraction layer created by the engine, which functions as an isolated execution environment. In particular, in the case of a client that runs on the browser, the application has at its disposal only those resources offered by the browser. Basic features, such as interacting with page elements and requesting files over HTTP, are always available. Resources that may contain sensitive information, such as access to local files, geographic location, camera, and microphone, require explicit user authorization before the application is able to use them.
Languages of a Web Client
The central element of a web application client that runs on the server is the HTML document. In addition to presenting the interface elements that the browser displays in a structured way, the HTML document contains the addresses for all files required for the correct presentation and operation of the client.
HTML alone does not have much versatility to build more elaborate interfaces and does not have general-purpose programming features. For this reason, an HTML document that should function as a client application is always accompanied by one or more sets of CSS and JavaScript.
The CSS can be provided as a separate file or directly in the HTML file itself. The main purpose of CSS is to adjust the appearance and layout of the elements of the HTML interface. Although not strictly necessary, more sophisticated interfaces usually require modifications to the CSS properties of the elements to suit their needs.
JavaScript is a practically indispensable component. Procedures written in JavaScript respond to events in the browser. These events can be caused by the user or non-interactive. Without JavaScript, an HTML document is practically limited to text and images. Using JavaScript in HTML documents allows you to extend interactivity beyond hyperlinks and forms, making the page displayed by the browser like a conventional application interface.
JavaScript is a general-purpose programming language, but its main use is in web applications. The features of the browser execution environment are accessible through JavaScript keywords, used in a script to perform the desired operation. The term document
, for example, is used in JavaScript code to refer to the HTML document associated with the JavaScript code. In the context of the JavaScript language, document
is a global object with properties and methods that can be used to obtain information from any element on the HTML document. More importantly, you can use the document
object to modify its elements and to associate them with custom actions written in JavaScript.
A client application based on web technologies is multiplatform, because it can run on any device that has a compatible web browser.
Being confined to the browser, however, imposes limitations on web applications compared to native applications. The intermediation performed by the browser allows higher level programming and increases security, but also increases the processing and memory consumption.
Developers are continually working on browsers to provide more features and improve the performance of JavaScript applications, but there are intrinsic aspects to the execution of scripts such as JavaScript that impose a disadvantage on them compared to native programs for the same hardware.
A feature that significantly improves the performance of JavaScript applications running on the browser is WebAssembly. WebAssembly is a kind of compiled JavaScript that produces source code written in a more efficient, lower-level language, such as the C language. WebAssembly can accelerate mainly processor-intensive activities, because it avoids much of the translation performed by the browser when running a program written in conventional JavaScript.
Regardless of the implementation details of the application, all HTML code, CSS, JavaScript, and multimedia files must first be obtained from the server. The browser obtains these files just like an Internet page, that is, with an address accessed by the browser.
A web page that acts as an interface to a web application is like a plain HTML document, but adds additional behaviors. On conventional pages, the user is directed to another page after clicking on a link. Web applications can present their interface and respond to user events without loading new pages in the browser’s window. The modification of this standard behavior in HTML pages is done via JavaScript programming.
A webmail client, for example, displays messages and switches between message folders without leaving the page. This is possible because the client uses JavaScript to react to user actions and make appropriate requests to the server. If the user clicks on the subject of a message in the inbox, a JavaScript code associated with this event requests the content of that message from the server (using the corresponding API call). As soon as the client receives the response, the browser displays the message in the appropriate portion of the same page. Different webmail clients may adopt different strategies, but they all use this same principle.
Therefore, in addition to providing the files that make up the client to the browser, the server must also be able to handle requests such as that of the webmail client, when it asks for the content of a specific message. Every request that the client can make has a predefined procedure to respond on the server, whose API can define different methods to identify which procedure the request refers to. The most common methods are:
-
Addresses, through a Uniform Resource Locator (URL)
-
Fields in the HTTP header
-
GET/POST methods
-
WebSockets
One method may be more suitable than another, depending on the purpose of the request and other criteria taken into account by the developer. In general, web applications use a combination of methods, each in a specific circumstance.
The Representational State Transfer (REST) paradigm is widely used for communication in web applications, because it is based on the basic methods available in HTTP. The header of an HTTP request starts with a keyword that defines the basic operation to be performed: GET
,POST
, PUT
,DELETE
, etc., accompanied by a corresponding URL where the action will be applied. If the application requires more specific operations, with a more detailed description of the requested operation, the GraphQL protocol may be a more appropriate choice.
Applications developed using the client/server model are subject to instabilities in communication. For this reason, the client application must always adopt efficient data transfer strategies to favor its consistency and not harm the user experience.
The Server Side
Despite being the main actor in a web application, the server is the passive side of the communication, just responding to requests made by the client. In web jargon, server can refer to the machine that receives the requests, the program that specifically handles HTTP requests, or the recipient script that produces a response to the request. This latter definition is the most relevant in the context of web application architecture, but they are all closely related. Although they are only partially in the scope of the application server developer, the machine, operating system, and HTTP server cannot be ignored, because they are fundamental to running the application server and often intersect.
Handling Paths from Requests
HTTP servers, such as Apache and NGINX, usually require specific configuration changes to meet the needs of the application. By default, traditional HTTP servers directly associate the path indicated in the request to a file on the local file system. If a website’s HTTP server keeps its HTML files in the /srv/www
directory, for example, a request with the path /en/about.html
will receive the content of the file /srv/www/en/about.html
as a response, if the file exists. More sophisticated websites, and especially web applications, demand customized treatments for different types of requests. In this scenario, part of the application implementation is modifying HTTP server settings to meet application requirements.
Alternatively, there are frameworks that allow you to integrate the management of HTTP requests and the implementation of the application code in one place, allowing the developer to focus more on the application’s purpose than on platform details. In Node.js Express, for example, all request mapping and corresponding programming are implemented using JavaScript. As the programming of clients is usually done in JavaScript, many developers consider it a good idea from the perspective of code maintenance to use the same language for client and server. Other languages commonly used to implement the server side, either in frameworks or in traditional HTTP servers, are PHP, Python, Ruby, Java, and C#.
Database Management Systems
It is up to the discretion of the development team how the data received or requested by the client is stored on the server, but there are general guidelines that apply to most cases. It is convenient to keep static content—images, JavaScript and CSS code that do not change in the short term—as conventional files, either on the server’s own file system or distributed across a content delivery network (CDN). Other kinds of content, such as email messages in a webmail application, product details in a shopping application, and transaction logs, are more conveniently stored in a database management system (DBMS).
The most traditional type of database management system is the relational database. In it, the application designer defines data tables and the input format accepted by each table. The set of tables in the database contains all the dynamic data consumed and produced by the application. A shopping app, for example, may have a table that contains an entry with the details of each product in the store and a table that records items purchased by a user. The table of purchased items contains references to entries in the product table, creating relationships between the tables. This approach can optimize storage and access to the data, as well as allow queries in combined tables using the language adopted by the database management system. The most popular relational database language is the Structured Query Language (SQL, pronounced “sequel”), adopted by the open source databases SQLite, MySQL, MariaDB, and PostgreSQL.
An alternative to relational databases is a form of database that does not require a rigid structure for the data. These databases are called non-relational databases or simply NoSQL. Although they may incorporate some features similar to those found in relational databases, the focus is on allowing greater flexibility in storage and access to stored data, passing the task of processing that data to the application itself. MongoDB, CouchDB, and Redis are common non-relational database management systems.
Content Maintenance
Regardless of the database model adopted, applications have to add data and probably update it over the life span of the applications. In some applications, such as webmail, users themselves provide data to the database when using the client to send and receive messages. In other cases, such as in the shopping application, it’s important to allow the application’s maintainers to modify the database without having to resort to programming. Many organizations therefore adopt some kind of content management system (CMS), which allows non-technical users to administer the application. Therefore, for most web applications, it’s necessary to implement at least two types of clients: a non-privileged client, used by ordinary users, and privileged clients, used by special users to maintain and update the information presented by the application.
Guided Exercises
-
What programming language is used together with HTML to create web applications clients?
-
How does the retrieval of a web application differ from that of a native application?
-
How does a web application differ from a native application in access to the local hardware?
-
Cite one characteristic of a web application client that makes it distinct from an ordinary web page.
Explorational Exercises
-
What feature do modern browsers offer to overcome the poor performance of CPU-intensive web application clients?
-
If a web application uses the REST paradigm for client/server communication, which HTTP method should be used when the client requests the server to erase a specific resource?
-
Cite five server scripting languages supported by the Apache HTTP server.
-
Why are non-relational databases considered easier to maintain and upgrade than relational databases?
Summary
This lesson covers the concepts and standards in web development technology and architecture. The principle is simple: the web browser runs the client application, which communicates with the core application running in the server. Albeit simple in principle, web applications must combine many technologies to adopt the principle of client and server computing over the web. The lesson goes through the following concepts:
-
The role of web browsers and web servers.
-
Common web development technologies and standards.
-
How web clients can communicate with the server.
-
Types of web servers and server databases.
Answers to Guided Exercises
-
What programming language is used together with HTML to create web applications clients?
JavaScript
-
How does the retrieval of a web application differ from that of a native application?
A web application is not installed. Instead, parts of it run on the server and the client interface runs in an ordinary web browser.
-
How does a web application differ from a native application in access to the local hardware?
All access to the local resources, such as storage, cameras, or microphones, are mediated by the browser and require explicit user authorization to work.
-
Cite one characteristic of a web application client that makes it distinct from an ordinary web page.
The interaction with traditional web pages is basically restricted to hyperlinks and sending forms, while web application clients are closer to a conventional application interface.
Answers to Explorational Exercises
-
What feature do modern browsers offer to overcome the poor performance of CPU-intensive web application clients?
The developers can use WebAssembly to implement the CPU-intensive parts of the client application. WebAssembly code generally has better performance than traditional JavaScript, because it requires less translation of instructions.
-
If a web application uses the REST paradigm for client/server communication, which HTTP method should be used when the client requests the server to erase a specific resource?
REST relies on standard HTTP methods, so it should use the standard
DELETE
method in this case. -
Cite five server scripting languages supported by the Apache HTTP server.
PHP, Go, Perl, Python, and Ruby.
-
Why are non-relational databases considered easier to maintain and upgrade than relational databases?
Unlike relational databases, non-relational databases do not require data to fit rigid predefined structures, making it easier to implement changes in the data structures without affecting existing data.