# Serverless and Application service

### **Monolithic**

Everything is in one big program. Hard to change one part without affecting the whole thing.

* Example: A big store website where login, product catalog, checkout, and payment all exist in one app.
* Monolithic = a single chocolate cake: if one layer goes wrong, the whole cake is affected.

<figure><img src="https://1856860631-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsNc001Xcz63mWjGXymkd%2Fuploads%2FpeafX5vr1mgY2yTkILbX%2Fimage.png?alt=media&#x26;token=cc21e419-9444-4c16-88d2-581351f4d2b2" alt=""><figcaption></figcaption></figure>

### **Tiered architecture**

Tiered architecture (or n-tier architecture) is a way of organizing an application into layers (tiers), each with a specific job.

Common example: 3-tier architecture

1. Presentation Tier (Front-end) – What the user sees and interacts with.
   * Example: Website pages, mobile app screens.
2. Logic Tier (Application/Business Layer) – Where the app makes decisions and processes data.
   * Example: Calculating prices, validating login, processing orders.
3. Data Tier (Database) – Where all the information is stored and retrieved.
   * Example: User accounts, product inventory, transaction records.

Think of a restaurant:

* Waiter (Presentation) → takes your order.
* Chef (Logic) → cooks and prepares the food.
* Storage/Pantry (Data) → stores all ingredients.

This separation makes the system easier to maintain, update, and scale, compared to a single monolithic block.

<figure><img src="https://1856860631-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsNc001Xcz63mWjGXymkd%2Fuploads%2FpLeXgmyzItQ9T7hSxCzL%2Fimage.png?alt=media&#x26;token=30bbed0d-9334-4bac-9ffd-618e56583287" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1856860631-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsNc001Xcz63mWjGXymkd%2Fuploads%2FFVOmu16SaQemar600Ejy%2Fimage.png?alt=media&#x26;token=6cf59311-d35f-42f2-9ec5-b45024288faa" alt=""><figcaption></figcaption></figure>

### **Synchronous (Sync)**

* Things happen one after another.
* Each task waits for the previous one to finish before starting.
* Analogy: Standing in line at a shop — you wait until the cashier finishes with the person ahead before it’s your turn.
* Example in tech: A web request that waits until the server finishes and sends back a response.

### **Asynchronous (Async)**

* Tasks can happen independently, at the same time.
* One task doesn’t have to wait for another.
* Analogy: Ordering food online — you place the order and continue doing other things while the restaurant prepares your food.
* Example in tech: Sending an email — your app doesn’t wait until the email is delivered, it just queues it and moves on.

👉 In short:

* Sync = wait for it to finish
* Async = don’t wait, keep going

### **Microservices**

The app is broken into small independent parts (services), each doing one job.

* Example: One service handles login, another handles payments, another handles catalog. They can be updated without breaking the others.
* Microservices = separate cupcakes: each one can be fixed or replaced without touching the others.

<figure><img src="https://1856860631-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsNc001Xcz63mWjGXymkd%2Fuploads%2FVBwAd6ONkpBBjwF76Rts%2Fimage.png?alt=media&#x26;token=c2d8d372-5910-4249-bfc4-50353ae323c4" alt=""><figcaption></figcaption></figure>

### **Event-driven architecture (EDA)**

Event-driven architecture (EDA) is a way of designing software where things happen in response to events.

* An event is any significant action or change, like:

  * A user clicks a button
  * A new order is placed
  * A sensor detects motion

  How it works:

1. Event occurs → something happens in the system.
2. Event is captured → a component called an event listener notices it.
3. Event is processed → another component takes action based on the event.

Analogy:

* Think of a doorbell system:
  * Pressing the doorbell = event
  * Bell rings = listener reacts
  * You open the door = action triggered

Key points:

* Components don’t constantly check for changes—they only act when something happens.
* Makes the system fast, flexible, and scalable.

<figure><img src="https://1856860631-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsNc001Xcz63mWjGXymkd%2Fuploads%2FFBsMPcLa0NVm0Q4o0CiR%2Fimage.png?alt=media&#x26;token=23cc1c11-c0c0-4467-8c5c-89ffe6444bde" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1856860631-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FsNc001Xcz63mWjGXymkd%2Fuploads%2FdooUySyRmN5SQLjUobt7%2Fimage.png?alt=media&#x26;token=f2c98166-9e46-4994-a055-ee7f5cbf7852" alt=""><figcaption></figcaption></figure>
