Distributed System Layers: Online Banking System Example
1. Applications & Services Layer (User Interaction Layer)
Definition: The Applications & Services Layer is the topmost layer of a distributed system where
users interact directly with applications and access reusable services.
Components:
Applications:
Mobile banking app (Android, iOS)
Web banking portal
ATM interface
Services:
Authentication Service: Validates user login credentials
Account Service: Retrieves account balances and transaction history
Transaction Service: Handles money transfers, bill payments
Notification Service: Sends SMS/email alerts
Example Workflow:
1. User logs in via the mobile or web app
2. Authentication Service checks credentials
3. Account Service fetches account balance
4. Transaction Service completes the money transfer
5. Notification Service sends a confirmation to the user
Key Idea: This layer is user-facing and depends on underlying services to perform operations
reliably.
2. Middleware Layer (Communication and Coordination Layer)
Definition: The Middleware Layer is software that connects applications with backend services,
managing communication, coordination, and reliability across distributed components.
Functions:
Message passing between applications and backend services
Request routing to appropriate servers
Load balancing for high traffic
Fault tolerance and concurrency control
Practical Examples:
Apache Kafka / RabbitMQ: Queues transaction requests for reliable processing
gRPC / REST APIs: Enable remote communication between mobile apps and backend
services
API Gateway / Service Mesh: Routes requests, handles authentication, logging, and
retries
Key Idea: Middleware hides network complexity and ensures reliable communication between
distributed system components.
3. Operating System Layer (Resource Management Layer)
Definition: The Operating System Layer manages hardware resources and provides a stable
runtime environment for applications and middleware.
Functions:
CPU scheduling, memory management, and storage management
Network management and communication handling
Process isolation and security for concurrent requests
Ensures data consistency for multiple transactions
Practical Examples:
Linux Servers: Host transaction services, databases, and middleware
Windows Server: May host web portals or additional services
Key Idea: The OS allocates resources efficiently and ensures safe and secure execution of
distributed services.
4. Hardware Layer (Physical Foundation Layer)
Definition: The Hardware Layer provides the physical computing, storage, and networking
infrastructure for a distributed system.
Components:
Servers: Dell PowerEdge or HPE ProLiant running banking services
Storage: SAN/NAS storing account data and transaction logs
Network Devices: Routers, switches, firewalls connecting servers and clients
Client Devices: Smartphones, laptops, and ATMs accessing banking services
Example Workflow:
1. Request from a mobile app travels over the network
2. Processed on a server
3. Data retrieved from storage
4. Response delivered back to the client
Key Idea: Hardware provides the resources and connectivity needed for all other layers to
function.
🔹 Logical Workflow Summary
Step Layer Action
1 Application Layer User initiates money transfer via mobile app
2 Middleware Layer Request is routed to correct server and queued reliably
3 Operating System Server OS manages CPU, memory, database access, and security
Layer checks
4 Hardware Layer Servers retrieve/update account data; network delivers response
to the client
Overall Key Point: Each layer has a distinct role but works together to provide a reliable, secure,
and scalable online banking experience.
🏦 Full Package Analysis: Withdrawing 1000 Birr Using Four Distributed System Layers
👉 Scenario: A customer withdraws 1000 Birr from an ATM or mobile banking system.
👉 We analyze who performs what from start to finish across the four DS layers.
🔷 1) Applications & Services Layer (User Interaction)
Definition: This layer contains user-facing applications and business services. It interacts directly
with the customer and initiates requests.
Components Involved
Applications
Mobile banking app
Web banking portal
ATM interface
Services
Authentication Service → verifies PIN/password
Account Service → checks balance
Transaction Service → processes withdrawal
Notification Service → sends SMS receipt
🔹 What Happens Here?
1. Customer inserts card or opens app
2. Enters PIN/password
3. Selects Withdraw → 1000 Birr
4. Application sends withdrawal request
👉 No money moves yet — only a request is created.
🔷 2) Middleware Layer (Communication & Coordination)
Definition: This layer manages communication between applications and backend systems. It
ensures reliability, routing, and coordination.
Functions
Request routing to correct bank server
Security checks (tokens, session validation)
Load balancing
Transaction coordination
Failure handling
Logging
🔹 What Happens Here?
1. Withdrawal request reaches bank network
2. Middleware verifies session validity
3. Routes request to appropriate banking service
4. Ensures transaction is processed exactly once
5. Coordinates distributed components
👉 If one server is busy, another may handle the request.
🔷 3) Operating System Layer (Resource Management)
Definition: The OS controls hardware resources and runs banking software processes.
Responsibilities
CPU scheduling
Memory management
Disk operations
Process isolation
Device control (ATM hardware)
Security enforcement
🔹 What Happens Here?
1. Server OS runs banking application processes
2. Allocates CPU and memory to transaction
3. Handles database access requests
4. Controls ATM devices (card reader, keypad, dispenser)
5. Ensures concurrent transactions run safely
👉 Multiple customers can withdraw simultaneously.
🔷 4) Hardware Layer (Physical Execution)
Definition:
Physical infrastructure that performs the actual computation and cash handling.
Components
Server Side
Banking servers
Storage systems (databases)
Network routers/switches
Client Side (ATM)
Card reader
Cash dispenser
Receipt printer
Display and keypad
Network interface
🔹 What Happens Here?
1. Server accesses account data from storage
2. Database updates balance (−1000 Birr)
3. ATM dispenser releases cash
4. Receipt is printed
5. Network sends confirmation back
👉 Physical money is delivered at this stage.
OSI Model Layers with Examples
The OSI (Open Systems Interconnection) Model is a conceptual framework used to understand
and design how different networking systems communicate. It has 7 layers, each with specific
functions and examples.
1. Physical Layer
Definition: Responsible for transmitting raw bits over physical media (cables, wireless signals).
It defines electrical, optical, and mechanical aspects.
Functions:
Converts data into electrical/optical signals
Manages physical connections
Handles voltage levels, cable types, and data rates
Examples:
Ethernet cables (Cat5, Cat6)
Fiber optic cables
Wi-Fi signals, Bluetooth signals
Hubs and repeaters
2. Data Link Layer
Definition: Ensures reliable transmission of data frames between two directly connected nodes
and handles error detection and correction.
Functions:
Frames data from the physical layer
Provides error detection (CRC) and flow control
Manages MAC addressing
Examples:
Switches and bridges
Ethernet (MAC addresses)
Wi-Fi (802.11 protocol)
3. Network Layer
Definition: Determines how data is routed and delivered between devices across different
networks.
Functions:
Logical addressing (IP addressing)
Routing and forwarding packets
Handling congestion and fragmentation
Examples:
IP (IPv4, IPv6)
Routers
ICMP (used in ping)
4. Transport Layer
Definition: Provides end-to-end communication and ensures reliable data transfer between
applications.
Functions:
Segmenting and reassembling data
Error detection and recovery
Flow control and congestion control
Examples:
TCP (Transmission Control Protocol)
UDP (User Datagram Protocol)
Port numbers for applications (HTTP: 80, HTTPS: 443)
5. Session Layer
Definition: Manages sessions or connections between applications on different devices.
Functions:
Establishes, maintains, and terminates sessions
Synchronizes communication between applications
Manages dialogue control (half-duplex/full-duplex)
Examples:
NetBIOS sessions
RPC (Remote Procedure Call)
PPTP (VPN sessions)
6. Presentation Layer
Definition: Translates data between the application layer and the network. Handles data format,
encryption, and compression.
Functions:
Data translation (e.g., ASCII to EBCDIC)
Data encryption and decryption
Data compression and decompression
Examples:
SSL/TLS (for secure communication)
JPEG, GIF, PNG image formats
MPEG, MP3 media formats
7. Application Layer
Definition: Provides network services directly to end-user applications.
Functions:
Supports application services like file transfer, email, and browsing
Interacts with software applications to enable network communication
Examples:
HTTP/HTTPS (web browsing)
SMTP/POP3/IMAP (email)
FTP (file transfer), DNS (domain name resolution)
🔹 Summary Table of OSI Layers
Layer Function Practical Example
7. Provides services to applications Web browser (HTTP/HTTPS), Email
Application (SMTP, IMAP)
6. Data translation, encryption, SSL/TLS, JPEG, MP3
Presentation compression
5. Session Manages sessions and dialogues NetBIOS, RPC, VPN sessions
4. Transport Reliable end-to-end TCP, UDP, Port numbers
communication
3. Network Routing and addressing IP, Routers, ICMP
2. Data Link Reliable node-to-node transfer Switches, Ethernet MAC addresses, Wi-Fi
1. Physical Physical transmission of bits Cables, Wi-Fi signals, Hubs
Key Takeaway: The OSI model provides a structured framework for understanding network
communication, with each layer focusing on specific tasks and responsibilities.
CPU Scheduling in Operating Systems
1. Definition
CPU Scheduling is a process in an operating system that decides which process in the ready queue
will get access to the CPU next. It is crucial in multiprogramming and multitasking environments
to ensure efficient CPU utilization and process management.
Key Idea: The CPU can execute only one process at a time per core, so scheduling is used to
maximize efficiency and reduce waiting time.
Important Terms:
Arrival Time (AT): Time at which a process arrives in the ready queue
Burst Time (BT): CPU time required by a process
Finish Time (FT): Time at which process completes execution
Turnaround Time (TAT): Total time spent in system
[TAT = FT - AT]
Waiting Time (WT): Time process spends waiting in ready queue
[WT = TAT - BT]
Response Time (RT): Time from submission to first execution (for FCFS same as WT)
2. Scheduling Criteria
The effectiveness of CPU scheduling is measured using the following criteria:
CPU Utilization: Keep the CPU as busy as possible
Throughput: Number of processes completed per unit time
Turnaround Time: Time taken from submission to completion of a process
Waiting Time: Total time a process spends waiting in the ready queue
Response Time: Time from submission until the first response is produced
3. Types of CPU Scheduling
A. First-Come, First-Served (FCFS)
Definition: Processes are executed in the order they arrive in the ready queue
Practical Example: Queue at a bank teller
Characteristics: Simple, non-preemptive, can cause convoy effect
B. Shortest Job Next (SJN) / Shortest Job First (SJF)
Definition: Executes the process with the shortest burst time first
Characteristics: Can be preemptive or non-preemptive
Example: Printing jobs in a printer queue prioritized by size
C. Round Robin (RR)
Definition: Each process is assigned a fixed time quantum in a cyclic order
Characteristics: Preemptive, suitable for time-sharing systems
Example: Time slices for CPU in Windows or Linux multitasking
D. Priority Scheduling
Definition: Each process is assigned a priority, CPU allocated to the highest priority
Characteristics: Can be preemptive or non-preemptive, starvation possible
Example: OS gives higher priority to system processes over user processes
E. Multilevel Queue Scheduling
Definition: Processes are divided into multiple queues based on priority or type
Example: Interactive processes in one queue, batch processes in another
4. Practical Workflow Example
1. Processes arrive in the ready queue
2. CPU Scheduler selects a process based on the chosen algorithm (FCFS, SJF, RR, etc.)
3. Process executes on CPU
4. If preemptive, scheduler may interrupt process after time quantum or if a higher priority
process arrives
5. Process completes and leaves CPU; next process selected
Example Scenario (Round Robin):
Time Quantum = 5 ms
Process P1 arrives → CPU executes 5 ms → P1 moves to back of queue if not finished
Next process P2 executes 5 ms, and so on
5. Summary Table of CPU Scheduling
Algorithm Type Key Feature Example
FCFS Non-preemptive First process in queue Bank teller queue
executes first
SJF Preemptive / Non- Shortest CPU burst first Print jobs by size
preemptive
Round Robin Preemptive Time slices assigned Multi-user time-sharing
cyclically system
Priority Preemptive / Non- Highest priority executes System processes over
preemptive first user processes
Multilevel Preemptive / Non- Multiple queues for Interactive vs batch
Queue preemptive process types processes
Deadlock
Definition: A deadlock is a situation where two or more processes are unable to proceed because
each is waiting for a resource held by another process. In other words, the processes are stuck
indefinitely, and none can complete its execution.
Example of Deadlock
1. Simple Resource Example
Two processes, P1 and P2, need two resources, R1 and R2.
Step 1: P1 acquires R1, P2 acquires R2.
Step 2: P1 requests R2 → waits (held by P2).
Step 3: P2 requests R1 → waits (held by P1).
Result: Both P1 and P2 are blocked → deadlock occurs.
2. Necessary Conditions for Deadlock (Coffman Conditions)
For a deadlock to occur, all four conditions must hold simultaneously/ at the same time.
1. Mutual Exclusion: At least one resource must be non-sharable (only one process can use
it at a time).
2. Hold and Wait: A process is holding at least one resource and waiting for additional
resources held by others.
3. No Preemption: Resources cannot be forcibly taken away from a process; the process must
release them voluntarily.
4. Circular Wait: A set of processes are waiting in a circular chain, where each process waits
for a resource held by the next process in the chain.
Necessary Conditions for Deadlock (Why Deadlock Happens)
All four must be TRUE at the same time.
Condition Meaning (Simple) Example
Mutual Exclusion Resource cannot be shared Only one process uses printer
Hold and Wait Holding one, waiting for another Holding printer, waiting for scanner
No Preemption Cannot take resource away Must wait until released
Circular Wait Waiting in a circle P1→P2→P3→P1
Deadlock Prevention (How to STOP Deadlock)
👉 Prevent = Break at least ONE condition
Deadlock prevention works by making sure at least ONE of the four conditions can NEVER
happen.
1) Mutual Exclusion
Condition: Some resources cannot be shared (only one process can use them at a time).
Prevention Idea: Make resources sharable whenever possible.
Explanation:
If many processes can use a resource at the same time → no deadlock
But some resources MUST be exclusive
Examples:
✔️ Read-only file → many processes can read simultaneously
❌ Printer → only one process can print at a time
👉 Therefore, mutual exclusion cannot be removed for non-sharable devices.
2) Hold and Wait
Condition: A process holds one resource while waiting for another.
Prevention Idea: Ensure a process never holds resources while requesting new ones.
✔️ Method A — Request All at Once
Process must request ALL required resources before execution starts
If all are available → execution begins
Otherwise → process waits
Example: Process needs Printer + Scanner
➡️ Must get both before starting
➡️ Cannot request Scanner later
Problems:
Resources may stay unused
Low resource utilization
Starvation possible
✔️ Method B — Request Only When Holding None
Process must release all resources before requesting new ones
Example: P1 holds Printer
Needs Scanner
➡️ Must release Printer first
➡️ Then request Scanner
3) No Preemption
Condition: Resources cannot be taken away from a process.
Prevention Idea: Allow the OS to TAKE resources back.
Explanation:
If a process holding resources requests another unavailable resource:
➡️ OS forces it to release what it already holds
➡️ Process waits until all needed resources become available
Example: P1 holds Printer
Requests Scanner (busy)
➡️ OS takes Printer back
➡️ P1 waits
➡️ Later P1 gets Printer + Scanner together
4) Circular Wait
Condition: Processes wait in a circular chain.
P1 → waits for P2
P2 → waits for P3
P3 → waits for P1
Prevention Idea:
Give resources a fixed global order.
Explanation:
Assign numbers to resource types
Processes must request resources only in increasing order
Example Resource Order:
1. Scanner
2. Printer
3. Disk
✔️ Allowed request: Scanner → Printer → Disk
❌ Not allowed: Printer → Scanner
👉 Because backward requests could create a cycle.
Sorting
1. Bubble Sort (Bubble Sort – The Simplest
How it works:
Compare each pair of adjacent elements.
Swap them if they are in the wrong order.
After one pass, the largest element “bubbles up” to the end.
Repeat until the array is sorted.
Example Original: [4, 2, 8, 6, 9, 10, 3, 5]
Phase 1: Compare each pair
o 4 & 2 → swap → [2, 4, 8, 6, 9, 10, 3, 5]
o 4 & 8 → no swap
o 8 & 6 → swap → [2, 4, 6, 8, 9, 10, 3, 5]
o 8 & 9 → no swap
o 9 & 10 → no swap
o 10 & 3 → swap → [2, 4, 6, 8, 9, 3, 10, 5]
o 10 & 5 → swap → [2, 4, 6, 8, 9, 3, 5, 10]
Phase 2: Repeat
[2, 4, 6, 8, 3, 5, 9, 10] → Phase 3: [2, 4, 6, 3, 5, 8, 9, 10] → Phase 4: [2, 4, 3, 5, 6, 8, 9,
10] → Phase 5: [2, 3, 4, 5, 6, 8, 9, 10]
✅ Sorted array: [2, 3, 4, 5, 6, 8, 9, 10]
2. Selection Sort – Look for the Minimum
How it works:
Divide array into sorted and unsorted parts.
Find the smallest element in the unsorted part.
Swap it with the first element of the unsorted part.
Repeat until the array is sorted.
Original: [4, 2, 8, 6, 9, 10, 3, 5]
Step 1: Min = 2 → swap with 4 → [2, 4, 8, 6, 9, 10, 3, 5]
Step 2: Min = 3 → swap with 4 → [2, 3, 8, 6, 9, 10, 4, 5]
Step 3: Min = 4 → swap with 8 → [2, 3, 4, 6, 9, 10, 8, 5]
Step 4: Min = 5 → swap with 6 → [2, 3, 4, 5, 9, 10, 8, 6]
Step 5: Min = 6 → swap with 9 → [2, 3, 4, 5, 6, 10, 8, 9]
Step 6: Min = 8 → swap with 10 → [2, 3, 4, 5, 6, 8, 10, 9]
Step 7: Min = 9 → swap with 10 → [2, 3, 4, 5, 6, 8, 9, 10]
✅ Sorted array: [2, 3, 4, 5, 6, 8, 9, 10]
3. Insertion Sort – Like Sorting Cards
How it works:
Take one element at a time.
Insert it into its correct position among the already sorted part of the array.
Original: [4, 2, 8, 6, 9, 10, 3, 5]
Step 1: 4 → [4] | 2 8 6 9 10 3 5
Step 2: 2 → insert before 4 → [2, 4] | 8 6 9 10 3 5
Step 3: 8 → insert → [2, 4, 8] | 6 9 10 3 5
Step 4: 6 → insert before 8 → [2, 4, 6, 8] | 9 10 3 5
Step 5: 9 → insert → [2, 4, 6, 8, 9] | 10 3 5
Step 6: 10 → insert → [2, 4, 6, 8, 9, 10] | 3 5
Step 7: 3 → insert before 4 → [2, 3, 4, 6, 8, 9, 10] | 5
Step 8: 5 → insert before 6 → [2, 3, 4, 5, 6, 8, 9, 10]
✅ Sorted array: [2, 3, 4, 5, 6, 8, 9, 10]
4. Merge Sort – Divide and Conquer
How it works:
Split array in half until each sub-array has 1 element.
Merge sub-arrays back in sorted order.
Idea: Divide → Sort → Merge
Original: [4, 2, 8, 6, 9, 10, 3, 5]
Step 1: Divide
[4, 2, 8, 6] and [9, 10, 3, 5]
Step 2: Divide again
[4, 2], [8, 6] | [9, 10], [3, 5]
[4] [2], [8] [6], [9] [10], [3] [5]
Step 3: Merge & Sort
[4] [2] → [2, 4]
[8] [6] → [6, 8]
[2, 4] + [6, 8] → [2, 4, 6, 8]
[9] [10] → [9, 10]
[3] [5] → [3, 5]
[3, 5] + [9, 10] → [3, 5, 9, 10]
Step 4: Final Merge
[2, 4, 6, 8] + [3, 5, 9, 10] → [2, 3, 4, 5, 6, 8, 9, 10]
✅ Sorted array: [2, 3, 4, 5, 6, 8, 9, 10]
Notes: Always O(n log n), stable, good for large datasets.
5. Quick Sort – Partitioning
How it works:
Pick a pivot element.
Partition array → smaller left, larger right.
Recursively sort left & right.
Original: [4, 2, 8, 6, 9, 10, 3, 5]
Step 1: Pivot = 5 → Partition: [4, 2, 3] | 5 | [8, 6, 9, 10]
Step 2: Left [4, 2, 3] pivot = 3 → [2] | 3 | [4]
Step 3: Right [8, 6, 9, 10] pivot = 10 → [8, 6, 9] | 10 | []
Step 4: [8, 6, 9] pivot = 9 → [8, 6] | 9 | []
Step 5: [8, 6] pivot = 6 → [ ] | 6 | [8]
✅ Combine all → [2, 3, 4, 5, 6, 8, 9, 10]
6. Heap Sort
How it works:
1. Build a max heap from the array. (Parent node ≥ children)
2. Swap the largest element (root) with the last element.
3. Reduce the heap size by 1 and heapify the root to maintain max heap.
4. Repeat until the heap is empty → array sorted in ascending order.
Idea: Build max-heap → repeatedly remove max → sorted array
Original: [4, 2, 8, 6, 9, 10, 3, 5]
Step 1: Build max-heap → [10, 9, 8, 6, 2, 4, 3, 5]
Step 2: Swap max with last → [5, 9, 8, 6, 2, 4, 3, 10] → Heapify → [9, 6, 8, 5, 2, 4, 3,
10]
Step 3: Swap max 9 → [3, 6, 8, 5, 2, 4, 9, 10] → Heapify → [8, 6, 3, 5, 2, 4, 9, 10]
Step 4: Swap max 8 → [4, 6, 3, 5, 2, 8, 9, 10] → Heapify → [6, 5, 4, 3, 2, 8, 9, 10]
Continue → [2, 3, 4, 5, 6, 8, 9, 10]
Algorithm Best Case Average Worst Memory Method Ease of
Case Case Usage Implement
Bubble Sort O(n) (sorted) O(n²) O(n²) Low Exchanging Very Easy
Selection Sort O(n²) O(n²) O(n²) Low Selection Very Easy
Insertion Sort O(n) (sorted) O(n²) O(n²) Low Insertion Moderate
Merge Sort O(n log n) O(n log n) O(n log n) High Merge Complex
Quick Sort O(n log n) O(n log n) O(n²) Medium Partition Complex
Heap Sort O(n log n) O(n log n) O(n log n) Low Heapify Most Complex