0% found this document useful (0 votes)
197 views

Project (BS Software Engineering) : Software Design and Architecture

WhatsApp is a mobile messaging app that allows users to exchange messages without paying for SMS. It was founded by former Yahoo employees and initially launched for Android. WhatsApp collects user account information and communicates with internal servers to process and deliver messages. The app supports messaging, calls, groups, broadcasts and privacy controls. It must handle large user volumes, maintain privacy, and perform reliably under various conditions.

Uploaded by

Najam Ul Saqib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
197 views

Project (BS Software Engineering) : Software Design and Architecture

WhatsApp is a mobile messaging app that allows users to exchange messages without paying for SMS. It was founded by former Yahoo employees and initially launched for Android. WhatsApp collects user account information and communicates with internal servers to process and deliver messages. The app supports messaging, calls, groups, broadcasts and privacy controls. It must handle large user volumes, maintain privacy, and perform reliably under various conditions.

Uploaded by

Najam Ul Saqib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Software Design And Architecture

Project
(BS Software Engineering)
Section 6A
Submitted To Sir Khawaja Sarmad
Project Name WhatsApp
Team Members • Iman Ishfaq (Bsem-f18-125) - Leader
• Najam-Ul-Saqib (Bsem-f18-007)
• Ameer Hamza (Bsem-f18-039)

Introduction:

1|Page
Software Design And Architecture

WhatsApp is a mobile messaging app that allows you to exchange messages without paying for
SMS. WhatsApp was founded by John Kom and Brian Acton, former employees of Yahoo Inc.
WhatsApp was initially launched for Android mobile devices. It delivers messages via Wi-Fi, as it
is an Internet-based app. WhatsApp on a smartphone is linked to a user's account. It collects
information about a simple account transaction (for example, sent messages, received
messages, media transmission, and network usage), talking to the internal server to process the
messages Communicate and receive the reply to the recipient. Send a message WhatsApp
provides their software to their server. On-premises server software needs to keep records and
provide adequate security regulations. The software must handle simultaneous access with the
same user.

Features
Account

The user must have a device on which to run the app. This device can run on either android,
iOS, Blackberry, Windows or Symbian. The user account is linked to the contact information
provided at the beginning of the application. The user can only contact this information.

Messages and Calls

Senders can send messages easily and for free. With it, we can send contacts, word documents,
photos, videos, etc. We can talk on the phone with our loved ones who are far away from us
through WhatsApp, either by voice or video call. We can also group, chat and make conference
calls with our friends and family.

Network Usage

The user should be online at any time to enjoy the benefits of Seamless WhatsApp. WhatsApp
uses far fewer network resources than any other chat app available in the market. WhatsApp
also gives the user the option to restrict resources to incoming media.

Recipient

WhatsApp can be used to communicate with more than one user at any one time. The recipient
should also use the application at the other end of the conversation. The contact information
associated with the WhatsApp account must be stored in the user's contacts to start a new
conversation with the recipient.

Group
A group of 1-256 users can be added to a group and chat with them at the same time. Any user
in a group can add new members to the group, no more than 150. Only the group administrator

2|Page
Software Design And Architecture

has executive permission to remove a member from this group. Group Admin may also grant
admin permissions to other members of the group.
Broadcast Messages
Effective Broadcast Same Messages If You Have 5-6 Effects Same Time With Broadcast Option.
The users were receiving contact information.
Privacy
WhatsApp provides seamless ways to protect user privacy. The user can specify which
information is available to other users and which information is not available. Information such
as last appearance, profile picture and status can be shown to everyone, just contacts, or
anyone. Backup:
An encrypted backup for all conversations is stored in the cloud in the case of Android devices
and BlackBerry devices, and in the case of iOS devices. Backups are encrypted to prevent
misuse of app metadata.
Last Seen, Profile Picture, Status, Receipts:

The user can add a profile picture to indicate its appearance. The user has last seen the last time
the user used the application. Status refers to a written statement about oneself, one's
condition, or one's mood, which depends on the use of all its recipients. Receipts indicate the
status of the message being sent to any recipient. A receipt indicating that the message was
sent by a user. The double receipt indicates that the other party has received the message. The
blue receipt indicates that the recipient has read the message.

Functional Requirements
User Registration
The user should be able to register for the application through a valid phone number. Upon
installing the application, the user will be asked to register their phone number. If the user skips
this step, the application should close. The user's phone number will be the unique identifier of
his account on the WhatsApp.

Adding New Contacts


The app should track all the contacts from the user's phonebook. If a contact has a WhatsApp
user account, these contacts will be automatically added to the user's contact list on WhatsApp.
If none of the contacts are registered on WhatsApp yet, the user should be provided with an
invitation option that sends regular text messages to the contacts with WhatsApp in the Google
contact store. It is requested to join WhatsApp.

3|Page
Software Design And Architecture

Send Message
The user should be able to send instant messages to any contact in his WhatsApp contact list.
The user should be notified when the message is successfully delivered to the recipient.

Send Attachments
User must be able to send audio, video and image files as attachments. Audio formats that the
app should support: WAV MP3 video formats that the app supports: AVMP4 Fluffy GIF image
formats that the app supports: File size should not be more than 2MB per message Broadcast
Message

You should be able to set up a user contact group. User must be able to broadcast messages in
these groups. The user must be able to determine if the intended recipient has read the
message. If the recipient reads the message, two tickets will be displayed once the message has
been read.

Non-Functional Requirements/ Quality Attributes


Scalability
WhatsApp should be able to provide instant messaging services to 1 billion users at any given
time. Privacy Messages shared between users should be encrypted to maintain privacy.

Robustness
In case user’s device crashes, a backup of their chat history must be stored on remote database
servers to

 Enable recoverability  Performance


Application must be lightweight and must send messages instantly.

Performance Requirements
It must be able to perform in adverse conditions extremely slow internet connections and low
battery on device. Uninterrupted connections High data transfer rate

Security Requirements
WhatsApp provides encryption so as to prevent unauthorized access to a message midway. It
use256-Bit SSL encryption to secure data between two users.

Software Quality Attributes


Availability

4|Page
Software Design And Architecture

The WhatsApp internal Server has to be available 24 hours a day.

Security
The Application should provide maximal security in order to make that much more transparent
there are the following requirements: It must be impossible to plug into the internal server
network.

Maintainability
Only maintainers are allowed to connect into internal servers.

5|Page
Software Design And Architecture

Use Case diagram

6|Page
Software Design And Architecture

Activity Diagram

Open WhatsApp

Click On New Chat NO


Button
Contact in recent chat list ?
Yes

Search for Contact Select Contact

Click on Paper Click Audio Image / Video


Press and hold
Icon Microphone Icon
Messege Type ?
Text

Type Text Messege Record Audio


No Messege
Media Exist ?

Yes Select File


Click On Camera Icon

No Yes

Happy With Messege ?

Swipe Left to delete Release Microphone


Recod Media Add Gifs or Emojis messege Icon

Add Caption

Send

7|Page
Software Design And Architecture

Information Flow Diagram


Agree WhatsApp
Create Account
Policies

Send Message
to Receiver

Waiting for Message

User
Message Not Message
Delivered Delivered

Read By receiver

Message Sent

State Mechanism Diagram

8|Page
Software Design And Architecture

Mobile Phone
Android, IOS or windows

Open WhatsApp Application


Select Person

Back To Home

Photo/Video Send Audio Message Text Message


Press Camera Press Mic Press Keyboard

Write Message
Press Camera

Capture Photo Make new Video/Photo

Speak Message
Voice
Press Send

Photo/Video Send Send

9|Page
Software Design And Architecture

Sequence Diagram (Login)

Actor WhatsApp Server

1. Click on Login Account ()


2. Login Successful ()

3. Login failed ()

4. Enter Phone Number ()

5. Enter OTP () DB
6. Enter Submit Button ()
7. Send new User information ()

8. Save User ()

10 | P a g e
Software Design And Architecture

Sequence Diagram (Send Message)

User Server User 2

1. Send Message()

2. Send ACK back()


Message
Appeared 3. Forward Message to reciever()
tobe sent
4. Send ACK for Delievery()
5. Delliever User2's ACK

Messege
Appeared
tobe Messege
Delivered Read by
User2

6. Send ACK for message Read()


7. Forword the ACK

Messege
Appeared as
Read by
User2

11 | P a g e
Software Design And Architecture

Sequence Diagram (WhatsApp Web)


WhatsApp
User WhatsApp Server User2
Web
1. Scan QR Code ()

2. Verify QR Code ()

3. Show Data on WhatsApp Web ()

4. Send Message ()

5. Verify Connectionn with Phone ()

6. Send Message to User 2()

7. Send ACK BAck ()

8. ACK Recieve () 9. Send Message to reciever ()

10. Send ACK back for Delievery ()


11. Send Back ACK ()

12. Recieve ACK ()

13. Show ACK on Web ()

Collaboration Diagram (Login)


1.login account()
4. enter phone no

5. enter OTP
6. enter submit button

12 | P a g e
User Application
Software Design And Architecture
3. Login Failed

login successful
Send New user
info

2. 7.

8. Save user info


Database Server

13 | P a g e
Software Design And Architecture

Collaboration Diagram (Send Message)


1. send message

User1
2. Send ACK back
5. Deliver user2's ACK
7. Forward User2's ACK

Server

3. Forward message to receiver

User2
4. Send ACK for delivery
6. Send ACK for message read

Collaboration Diagram (WhatsApp Web)


1. Scan QR code

User1 8. ACK Received


WhatsApp Mobile
12. ACK Received

2. verify code
3. show data on WhatsApp web

4. Send Message 6. Send message to user2


13. Show ACK on web 13. Show ACK on web

WhatsApp Web

7. Send ACK back


11. Send ACk Back

9. Send Message to receiver

User2 Server
10. Send ACK back for delivery

14 | P a g e
Software Design And Architecture

Class Diagram

User
-ID: String
-Name: String Message
+chat() Text
+Status() -Sender ID : String
+Calls() -Reciever ID : String -Message : String
+Settings() -Time : TimeStamp
-Message : String
-Encription : String
-File : file Audio
+Send()
+Recieve() -Duration : Time
+Delete()
+Document()
+Image()

Video
-Duration : Time

Group Call
-Group ID : String File
-Caller ID : String
-Group Name: String -Reciever ID : String
-Group profile: file -File : file
-Time : TimeStamp
+addGroup() -Encription : String
+groupSettings() +addPerson()
+addPerson() +endCall()
+removePerson() +loudSpeaker()
+sendMessage() +muteCall()
+videoCall()

Architecture pattern

We are using Client-Server Architecture pattern in our project. This pattern consists of two
parties; a server and multiple clients. The server component will provide services to multiple
client components. Clients request services from the server and the server provides relevant
services to those clients. Furthermore, the server continues to listen to client requests.

15 | P a g e
Software Design And Architecture

Explanation:
In this article we are going to explore the high level engineering and system architecture behind
Whatsapp App.

Before diving deep let’s understand ‘How communication works’?

General Communication Architecture

16 | P a g e
Software Design And Architecture

When two clients(A and B) want to communicate or send messages to each other, they first
know the address of each other(It may be IP,MAC or any customized unique identity) and they
exchange messages with each other over a network, in this case it is INTERNET.

But, what if the network is very large and number of clients are in millions or billions?

In a very large network it is very difficult to know the address of each and every client, In this
case to make this system more robust and highly available we need a component between the
clients called “SERVER”. The task of this server is to coordinate between all the clients
connected to it.

17 | P a g e
Software Design And Architecture

Client-Server based communication architecture.

After the introduction of server. All clients instead of making connection with each other they
make connection with the server.

In this scenario when a client(A) want to send message to other client(D), it first sends the
message to server and the server knows the address of other client(D),then it forwards the
message to other client(D) and vice versa.

This is the overview of the communication architecture. Lets design Actual System design of a
real time messaging system.

Requirements:
So, let’s list some of the features needed to be incorporated in whatsapp:

• Text Messaging.
• Media Support.
• Last Seen
• Message Encryption
• Telephony Services(Audio/Video)

18 | P a g e
Software Design And Architecture

Let’s start designing the system based on the application requirement.


Based upon the user base we need multiple servers to handle this much traffic, so instead of
one server we place multiple servers.

But the question is that, to which server the client will connect as there are multiple servers and
the client cannot connect randomly to any server. To overcome this issue we introduced a load
balancer between the client and the server.

Multiple Servers and load balancer architecture

After implementing multiple servers and load balancer, our system architecture is capable of
handling a large user base. Now when a client want to connect to the server, the connection
request first hits the load balancer and then the load balancer redirects the connection to a
server based on various parameters like load on individual servers etc.

19 | P a g e
Software Design And Architecture

Servers with Database

But our application also needs some storage mechanism to save some arbitrary state or data, to fulfill
this requirement we also added database which is accessible to all the servers.

But, what kind of connection is used?

Generally, this kind of system uses a DUPLEX Connection or Bidirectional Connection. As the
message can also be generated from the server, so bidirectional communication is required

Before moving ahead lets understand different connectivity scenarios and how the application
works.

1. When Sender is connected to server but not the receiver:

20 | P a g e
Software Design And Architecture

Sender is connected to server but receiver is not.

In this case when the receiver is not connected to the server, the message is stored in the
database and when the receiver connects to the server, the message is fetched from the
database and forwarded to the receiver.

2. When Sender is not Connected to the Server:

Client not connected and message is saved in device storage.

21 | P a g e
Software Design And Architecture

In this case when sender is not connected to the server, the message sent by the sender is
saved in the device local storage (it may be SQLite or anything else based on platform). And
when the sender goes online or connects to the serve the message is fetched from the local
storage and sent to the server.

3. When both clients are connected to the server:

Both Clients are connected to the server.

In this case when both the clients are connected to the server, the sender sends the message
and the server forwards that message to the receiver without storing the message to the
database or device local storage.

One thing which needs to be known is that the connection is always initiated by the client
because the server does not know the address of the client but the client knows the address of
the server.

How Sent, Delivered and Seen Works?

22 | P a g e
Software Design And Architecture

WhatsApp message status symbols

Sent: When we send a message and that message is received by WhatsApp server.

Delivered: When the message is delivered to the receiver from the WhatsApp server.

Seen: When the message is seen/opened by the receiver.

To incorporate all these status changes, every message has a unique ID to identify each
message and acknowledgement from the various events (sent / delivered /seen).

What happens inside the WhatsApp server when a client connects to the server?

23 | P a g e
Software Design And Architecture

When a client connects to the WhatsApp server, a process (or thread) is created with respect to
that client. This process is responsible for handling all the operations related to that client.

With every process, a queue (Highlighted with light green color) is associated which act as a
buffer for that process. After process creation, a table is created in the database to maintain the
record of PID (Process ID) and the associated Client.

How Last Seen Work?

Implementation of this feature is very simple and straightforward, It is just about maintaining a
record with Client ID and Timestamp.

A table containing client id and their last seen status

When we open WhatsApp in our smartphone, our application sends a pulse to server every 5

Seconds, and with every pulse last seen time is updated in the table. As the client disconnects
the last seen time exists in the record that is updated by the last pulse sent before closing the

app.

How the media sharing works?

For sharing, we don’t use the connection which is used for sending text messages because it is a
very lightweight connection and it cannot handle this much load.

Instead, WhatsApp uses a different server (like HTTP) to share media.

24 | P a g e
Software Design And Architecture

System design with HTTP Server

When we share a media, it gets uploaded to an HTTP Server over a different connection, after
successful upload, the HTTP server returns a hash or unique ID associated to that media and
that hash value is sent to the WhatsApp server. At the receiver end, the same thing works in a
reverse way, the receiver receives the hash value then it downloads the media from HTTP
server associated to that hash value.

The Telephony services also work in the same way just like media services, for this, we also use
a different server and use a different kind of connection like socket etc. for real-time
communication.

Design Pattern
Project Name: WhatsApp
We are using Singleton Design pattern in our project. Singleton is a creational design pattern
that lets you ensure that a class has only one instance, while providing a global access point to this
instance.

25 | P a g e
Software Design And Architecture

Justification:
In a typical Android app, there are many objects for which we only need one global instance,
whether you are using it directly or simply passing it to another class. Examples include caches,
OkHttpClient, HttpLoggingInterceptor, Retrofit, Gson, SharedPreferences, the repository class,
etc. If we were to instantiate more than one of these types of objects, we'd run into problems
like incorrect app behavior, resource overuse, and other confusing results.

We are using Singleton pattern and in singleton pattern we give global access in which everyone
can access this app. Some requirements are given below:

 One to one Chat: You can make a chat with your friends or any numbers which you have
in your contacts.
 Group Messaging: WhatsApp has Groups. Almost 200 people can enter to one group.
 Sent + Delivered + Read receipts: Here you can see tick marks coming in based on what
stage is the message on.
 Online / Last Seen: The person is online or the person last online status.
 Image Sharing: Images are going to share with messages. Here video sharing also
applied.
 Temporary/ Permanent Chats: This is for store some messages store someplace forever.
This will save your storage and so on. If you delete some chat and your friend delete the
same chat, those messages are lost forever.

I prefer singletons over Application because it helps keep an app much more organized and
modular -- instead of having one place where all of your global state across the app needs to be

26 | P a g e
Software Design And Architecture

maintained, each separate piece can take care of itself. Also the fact that singletons lazily
initialize (at request) instead of leading you down the path of doing all initialization up-front in
Application.onCreate () is good.

There is nothing intrinsically wrong with using singletons. Just use them correctly, when it
makes sense. The Android framework actually has a lot of them, for it to maintain per-process
caches of loaded resources and other such things.

Also for simple applications multithreading doesn't become an issue with singletons, because by
design all standard callbacks to the app are dispatched on the main thread of the process so
you won't have multi-threading happening unless you introduce it explicitly through threads or
implicitly by publishing a content provider or service I Binder to other processes.

Chatting System:

If we have just two devices on the same network which need to transfer messages between
each other then we need to know the address of both the devices and can exchange the
message directly. But when the number of devices and the number of networks increases then
it becomes increasingly difficult and we need to have a server in between that is responsible for
receiving/sending the messages to appropriate clients.

Last Seen:

Whenever a client is performing any activity such as sending a message, opening a new message,
uploading documents or making a phone call this recent activity along with the time stamp is recorded
for the user. With each new activity, the timestamp for the user is updated. Whenever a user B wants to
check the last seen of user A then it requests the database to get the timestamp of user A. If the
timestamp is within the range current time – threshold value(e.g. 1 minute) then we can display the
status as online else display the last seen as the timestamp of user A’s last activity.

WhatsApp supports 3 message acknowledgments: message sent, message delivered and message
read.

As soon as the server thread processes the message from the received message queue it sends the
client that the server received the message. When the receiver receives the message or reads the
message a new request is sent to the server which then updates the sender about the status of the
message.

Multimedia:

27 | P a g e
Software Design And Architecture

In a chat messaging system it’s common to share images, videos, and file attachments. These
could be a long-running process and should be separated into another micro service that could
handle such requests.

28 | P a g e

You might also like