Basic Concepts
Introduction of software application named Mini Mall
Mini Mall is a simple solution for local merchants to manage there
inventory online
,accept online payments
and generateinvoice
for there customers.
using this data mini mall helps merchant in
book keeping
,sales insights
andnotify about old stock to clear
.
Initial Setup
so initially we started with simple setup which consists of :
- Virtual Machine / Server: A server is nothing but a computer machine designed for compute, store, and manage data, devices, and systems over a network.
- Backend: consists of
API
to register merchant, manage inventory, create bill, get sales insights and many more. - Frontend: this piece mainly consists of
static files
such asHTML, CSS, JS
to serve User Interface. - Database: database consist of data to store merchant data, inventory data, bills data and sales transactions data.
- Web-server: software component that delivers static data like images, files, and text in response to client requests we are using Nginx here.
- Situation
- Issue
- Task
- Action
So far every thing is good, let's understand the situation
when user opens the web application using public_ip:
170.187.254.215
thenNGINX
as web server will serve the static files.we also have mobile applications for merchant which will notify the merchants about store such as payment status etc.
for mobile applications we are offering Rest API's with which data is rendered on mobile-app. Sample API request
curl -X GET
170.187.254.215:5000/api/inventory
Now let's understand the issue with current setup
High Latency: Data transfer between clients and servers can be slow, negatively impacting user experience.there is no
caching
mechanism.Security Vulnerabilities: Servers may be directly exposed to the internet, making them susceptible to security attacks and breaches.
Uneven Server Load: So tomorrow we can deploy more backend replicas which can run on different ports then we need some mechanism to balance load between all replicas.
Bad url structure: instead of this
170.187.254.215:5000/api/user
we need170.187.254.215/api/user
, so port should not be there.
Hence we need both our Backend and frontend should be serve on default
port: 80
.
Backend: 170.187.254.215/api/user
Frontend: 170.187.254.215/
Hence here comes the first system design concept
named
Reverse Proxy
.
Concept: Reverse Proxy
so after adding reverse proxy layer our backend is now behind the proxy server in this way we have make sure that all the traffic will went through the proxy layer and will provide some benefits as follows:
- Url Routing : so now we don't have to mention the
port
in the url instead we will just add the prefix/api
which in turn tell reverse proxy to hit the backend internally. - Rate Limiting: just by adding simple configuration we can mention the threshold to limit the request to the server.
- Caching: reverse proxy provides the caching mechanism and we can apply this just using some configuration including
proxy_path: where to store
,key_zone: tells about storage
,cache_key: how to create cache key
etc.for more info read here. - Load Balancing: so in future we can add multiple replicas so one replica runs at
4000
, second runs at5000
etc.so by mentioning the list of ports reverse proxy can balance the load between different replicas.
- Situation
- Issue
- Task
- Action
So far every thing is good, let's understand the situation
we hit the endpoint
170.187.254.215
for static content and to hit the backend API's we use enpoint:170.187.254.215/api
Now let's understand the issue with current setup
first issue is this IP is not user friendly we need specific name to use the application.
second issue is what if our virtual machine goes down and after starting new machine our public IP is changed.so we need a particular name to use application and it should point to the rigth IP under the hood.
Hence we need a specific name like minimall.com to use the application.
Hence here comes the next system design concept
named
Domain Name System
.
Concept: DNS(Domain Name System)
At this step we have purchased the domain and in Domain management dashboard we will add a record to map our public IP with domain name.
Record Type | Name | Value | TTL (Time-to-Live) |
---|---|---|---|
A | minimall.com | 170.187.254.215 | 3600 |
- Record Type: A (Address record), which maps domain names to IPv4 addresses.
- Name: The domain name is "minimall.com."
- Value: The associated IP address is 170.187.254.215.
- TTL (Time-to-Live): The information can be cached by DNS resolvers for up to 3600 seconds (1 hour) before needing to refresh.
Some Popular record types:
- A (Address): Maps a domain name to an IPv4 address.
- AAAA (IPv6 Address): Maps a domain name to an IPv6 address.
- CNAME (Canonical Name): Alias of one domain to another (used for subdomains).
- Situation
- Issue
- Task
- Action
So far every thing is good, let's understand the situation
so now we have nice domain and our sales team, onboarded some merchants and some of the merchants are actively managing there inventory and created some bills.
- now there is some users who is using our application.
Now let's understand the issue with current setup
for now there is no major issue but we need some visibility to get the performance metrics of the application.
This will assist in identifying the problem before users voice their complaints.
Hence we need a dashboard and a proper system to record the metrics for better visibility.
Hence here comes the next system design concept
named
Logging and Monitoring
.
Concept: Logging and Monitoring
At this step we need a system setup which will record:
- Logs: Produced by application. Types of Logs based on Level:
info, debug, error,warning
etc. - Metrics: Mainly tells about performance of
Application,Virtual Machine and Database
.main performace indicators are:CPU,Memory Utilization, Latency and Network metrics
.
Next thing we need a dashboard which mainly pull the record of logs and metrics from a
datasource/database
so that team can able to visualize and take actions.
Hence we can use Grafana or Kibana as our dashboarding tool.here we are using
Grafana
.
- Situation
- Issue
- Task
- Action
So far every thing is good, let's understand the situation
so now we have a nice dashboard where we can see metrics such as
CPU usage, RAM usage, Disk space
etc.we can also see the logs from dashboard which can helps us to see the
Error rates,Application health,Application behaviour
etc.
Now let's understand the current issue which we have observed.
first thing which we observed is High CPU Utilization where only 20% is idle CPU.
second thing is memory usage of virtual machine is constantly increasing.
Hence we need to add some resources mainly in terms of CPU and Memory and to do that we need to create a new instance which provide more Virtual CPU's and RAM(Memory).
Hence here comes the next system design concept
named