7.web Application Architecture
7.web Application Architecture
2. The Client
Web development is all about communication and sharing Information . In this case,
communication between two (2) parties, over the HTTP protocol:
The Server - This party is responsible for serving pages.
The Client - This party requests pages from the Server, and displays them to the user. In
most cases, the client is a web browser.
a. The User - The user uses the Client in order to surf the web, fill in forms, watch videos
online, etc.
3. Load balancing
Load balancing refers to efficient and skilful distribution of incoming network traffic across a group
of backend servers, also known as a server farm or server pool.
Modern high-traffic websites must serve hundreds of thousands, if not millions, of concurrent
requests from users or clients and return the correct text, images, video, or application data, all in a
fast and reliable manner. To cost-effectively scale to meet these high volumes, modern computing
best practice generally requires adding more servers.
❖ Upstream Module
In order to set up a round robin load balancer, we will need to use the nginx upstream module. We
will incorporate the configuration into the nginx settings.
Go ahead and open up your website’s configuration (in my examples I will just work off of the
generic default virtual host):
$sudo nano /etc/nginx/sites-available/default
• Restart nginx
$ sudo service nginx restart
As long as you have all of the virtual private servers in place you should now find that the load
balancer will begin to distribute the visitors to the linked servers equally.
Weight
One way to begin to allocate users to servers with more precision is to allocate specific weight to
certain machines. Nginx allows us to assign a number specifying the proportion of traffic that
should be directed to each server.
A load balanced setup that included server weight could look like this:
upstream backend {
server backend1.example.com weight=1;
server backend2.example.com weight=2;
server backend3.example.com weight=4;
}
The default weight is 1. With a weight of 2, backend 2.example will be sent twice as much traffic as
backend 1, and backend 3, with a weight of 4, will deal with twice as much traffic as backend 2 and
four times as much as backend 1.
Hash
IP hash allows servers to respond to clients according to their IP address, sending visitors back to
the same VPS each time they visit (unless that server is down). If a server is known to be inactive, it
should be marked as down. All IPs that were supposed to routed to the down server are then
directed to an alternate one.
The configuration below provides an example:
upstream backend {
ip_hash;
server backend1.example.com;
server backend2.example.com;
server backend3.example.com down;
}
Max Fails
Based on default round robin settings, nginx will continue to send data to the virtual private servers,
even if the servers are not responding. Max fails can automatically prevent this by rendering
unresponsive servers inoperative for a set amount of time.
There are two factors associated with the max fails: max_fails and fall_timeout. Max fails refers to
the maximum number of failed attempts to connect to a server should occur before it is considered
inactive. Fall_timeout specifies the length of that the server is considered inoperative. Once the time
expires, new attempts to reach the server will start up again. The default timeout value is 10
seconds.
Windows:
Download Installer Apache HTTP server here: (http://httpd.apache.org/download.cgi)
Be sure to download the apache_2.2.16-win32-x86-no_ssl MSI.
Note :the Apache HTTP server version may be different at the time of your installation
Linux:
On Ubuntu you can install the Apache HTTP server with the following command.
$ sudo apt-get install apache2
Starting Tomcat
Tomcat can be started by executing the following commands on the Windows machine −
%CATALINA_HOME%\bin\startup.bat
or
C:\apache-tomcat-5.5.29\bin\startup.bat
Tomcat can be started by executing the following commands on the Unix (Solaris, Linux, etc.)
machine −
$ cd CATALINA_HOME/bin/
$ ./startup.sh
or
$ cd /usr/local/apache-tomcat-5.5.29/bin/
$ ./startup.sh
After a successful startup, the default web-applications included with Tomcat will be available by
visiting http://localhost:8080/.
11. Database(MySQL)
A database is a separate application that stores a collection of data. Each database has one or more
distinct APIs for creating, accessing, managing, searching and replicating the data it holds. Other
kinds of data stores can also be used, such as files on the file system or large hash tables in memory
but data fetching and writing would not be so fast and easy with those type of systems.
Well, there’s tons of types of databases nowadays. Many companies develop their own databases to
adapt them to their needs.
First of all, there’s the relational databases, that’s where the industry started, they use table-like
schemes and store the data in disk. This kind of databases are pretty good to store business data. For
example MySQL, Postgres, SQL Server etc.
MySQL
MySQL is the most popular Open Source Relational SQL Database Management System. MySQL
is one of the best RDBMS being used for developing various web-based software applications.
Windows:
The default installation on any version of Windows is now much easier than it used to be, as
MySQL now comes neatly packaged with an installer. Simply download the installer package,
unzip it anywhere and run the setup.exe file. (https://dev.mysql.com/downloads/installer/ )
The default installer setup.exe will walk you through the trivial process and by default will install
everything under C:\mysql.
Linux:
To install it, simply update the package index on your server and install the default package with
apt-get.
▪ sudo apt-get update
▪ sudo apt-get install mysql-server
Note : Here we use linux as an OS
$ ALTER TABLE potluck ADD email Adding a column after a specific column
VARCHAR(40) AFTER name;
15. JBOSS
JBoss is a application server, is the most widely used Open Source application server on the market.
The highly flexible and easy-to-use server architecture has made JBoss the ideal choice for users
just starting out with J2EE, as well as senior architects looking for a customizable middleware
platform. The server binary and source code distributions are available from the SourceForge
repository. (http://sourceforge.net/projects/jboss). The ready availability of the source code allows
you to debug the server, learn its inner workings and create customized versions for your personal
or business use.
This chapter is a step-by-step tutorial that will show you how to install and configure JBoss 4.0.
Specifically, you will learn how to:
• Obtain updated binaries from the JBoss SourceForge project site
• Install the binary
• Test the installation
You will also learn about:
• The installation directory structure
• Key configuration files an administrator may want to use to customize the JBoss installation
• Obtaining the source code for the 4.0 release from the SourceForge CVS repository
• Building the server distribution.
Prerequisites
Before installing and running the server, check your system to make sure you have a working JDK
1.4+ installation. The simplest way to do this is to execute the java -version command to ensure that
the java executable is in your path, and that you are using Version 1.4 or higher. For example,
running this command with a 1.4.1 JDK would produce version number like the following.
16. RabbitMQ
RabbitMQ is open source message broker software (sometimes called message-oriented
middleware) that implements the Advanced Message Queuing Protocol (AMQP). The RabbitMQ
server is written in the Erlang programming language and is built on the Open Telecom Platform
framework for clustering and failover.
Note :For RabbitMQ installation guide follow the given link :
https://www.rabbitmq.com/configure.html
Note : For RabbitMQ code examples follow the given link:
https://www.rabbitmq.com/getstarted.html
Below example gives an idea about RabbitMQ as a middleware
This command should show that Memcached is running on the default port 11211.
To run Memcached server on a different port, run the command given below
$ memcached -p 11111 -U 11111 -u user -d
It should start the server and listen on TCP port 11111 and UDP port 11111 as a daemon process.
You can run multiple instances of Memcached server through a single installation.
Application Memcached DB
This architecture describes an approach to designing heavyweight web application for robust,
concurrent with fault-tolerance and distributed software structure. An app is robust when it can
work consistently with inconsistent data. For example: a maps application is robust when it can
parse addresses in various formats with various misspellings and return a useful location.
This web application architecture contains load balancing, static content handler, dynamic content
handler(NodeJS), Elastic search (For Indexing), Memcached,NoSQL Database (MongoDB).
Load Balancer:
Note: Web Application Architecture 1 give a clear idea for installing and configuring Nginx as
Load Balancer. Refer Web Application Architecture 1.
Node.js Runtime
The source code written in source file will be normal javascript code only. The Node.js interpreter
will be used to interpret and execute your javascript code.
Node.js distribution comes as a binary installable for SunOS , Linux, Mac OS X, and Windows
operating systems with the 32-bit (386) and 64-bit (amd64) x86 processor architectures.
Following section guides you on how to install Node.js binary distribution on various OS.
OS Archive name
Windows node-v6.11.0-x64.msi
Linux node-v6.11.0-linux-x86.tar.gz
Mac node-v6.11.0-darwin-x86.tar.gz
SunOS node-v6.11.0-sunos-x86.tar.gz
Note: In Linux, we can have installation directly from linux shell by using apt package manager.
following commands
sudo apt-get update
sudo apt-get install nodejs
If the package in the repositories suits your needs, this is all that you need to do to get set up with
Node.js. In most cases, you'll also want to also install npm, which is the Node.js package manager.
You can do this by typing:
•Create a js file named app.js on your machine (Windows or Linux) having the following code.
/* Hello, World! program in node.js */
console.log("Hello, World!")
Now execute app.js file using Node.js interpreter to see the result:
$ node app.js
If everything is fine with your installation, this should produce the following result:
Hello, World!
res.end('Hello World');
});
server.listen(8081);
Elasticsearch Installation
The steps for installation of Elasticsearch are as follows:
Step 1 − Check and Verify the minimum version of your java is installed your computer, it should
be java 7 or more updated version. You can check by doing the following:
Note −Please make sure, JAVA_HOME set, please set it in environment variables to “C:\Program
Files\Java\jre1.8.0_31” or the location where you installed java.
$ echo $JAVA_HOME
Step 3 − Installation process for Elasticsearch is very easy and described below for different OS −
• Windows OS − Unzip the zip package and the Elasticsearch is installed.
• UNIX OS − Extract tar file in any location and the Elasticsearch is installed.
Run update:
$ sudo apt-get update
Step 4 − Go to the Elasticsearch home directory and inside the bin folder. Run the elasticsearch.bat
file in case of windows or you can do the same using command prompt and through terminal in case
of UNIX run Elasticsearch file.
In Windows −
> cd elasticsearch-2.1.0/bin
> elasticsearch
In Linux −
$ cd elasticsearch-2.1.0/bin
$ ./elasticsearch
Step 5 − Default port for Elasticsearch web interface is 9200 or you can change it by changing
http.port inside elasticsearch.yml file present in bin directory. You can check if the server is up and
running by browsing http://localhost:9200. It will return a JSON object, which contains the
information about the installed Elasticsearch in the following way :
{
"name" : "Brain-Child",
"cluster_name" : "elasticsearch", "version" : {
"number" : "2.1.0",
"build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",
"build_timestamp" : "2015-11-18T22:40:03Z",
"build_snapshot" : false,
"lucene_version" : "5.3.1"
},
"tagline" : "You Know, for Search"
Note: Memcached description and installation are given in web application architecture-2 .please
refer web application architecture-2 for more details.
21.MongoDB
MongoDB is an open-source document-oriented database. MongoDB is one of highly used NoSQL
database. MongoDB is written in C++.
All the modern applications require big data, fast features development, flexible deployment and the
older database systems not enough competent, so the MongoDB is designed to fulfil the
requirement.
Now extract your downloaded file to c:\ drive or any other location.
Make sure the name of the extracted folder is mongodb-win32-i386-[version] or mongodb-win32-
x86_64-[version]. Here [version] is the version of MongoDB download.
Next, open the command prompt and run the following command.
C:\> move mongodb-win64-* mongodb
1 dir(s) moved.
C:\>
If you have to install the MongoDB at a different location, then you need to specify an alternate
path for \data\db by setting the path dbpath in mongod.exe. For the same, issue the following
commands.
In the command prompt, navigate to the bin directory present in the MongoDB installation folder.
The result will show waiting for connections message on the console output, which indicates that
the mongod.exe process is running successfully.
Run MongoDB:
Now to run the MongoDB, you need to open another command prompt and execute the following
command.
D:\Software\mongodb\bin>mongo.exe
MongoDB shell version: 2.4.6
connecting to: test
>db.test.save( { a: 1 } )
>db.test.find()
{ "_id" : ObjectId(5879b0f65a56a454), "a" : 1 }
>
This will show that MongoDB is installed and run successfully. Next time when you run
MongoDB, you need to issue only commands.
Create a list file for MongoDB ,create a /etc/apt/sources.list.d/mongodb.list file using the following
command.
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen'
| sudo tee /etc/apt/sources.list.d/mongodb.list
In the above installation, 3.4.5 is currently released MongoDB version. Make sure to install the
latest version always. Now MongoDB is installed successfully.
Start MongoDB
sudo service mongodb start
Stop MongoDB
sudo service mongodb stop
Restart MongoDB
sudo service mongodb restart
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Summary:
➢ Any Architectural design include Many point such as what (conceptual) parts does our app
consist of? How do the different parts communicate with each other? How do they depend
on each other?
➢ A well-defined Architecture consist of Many components which communicate hand to hand
with each other with higher accuracy and less fault tolerance.
➢ A web application architecture consist of many services such as load balancer, Message
broker(ActiveMQ/rabbitMQ), Elasticsearch, web server(Tomcat),Application
server(JBOSS),Node JS and different high level programming language such as Java, PHP,
python and Javascript etc.
➢ Above three different web application architectural design are given to understood the real
time web application design.
Conclusion:
The goal of Chapter was to provide a understanding of architectural design with necessary
background information for Web-based applications. Every architectural design will be different
based on the requirement and facilities(Technologies) used. Nowadays growing web-based
applications thus requires both scalable architectures and appropriate concepts for concurrent
programming.