# 💡 Scaling up to your first 1 Million Users 🚦

🎯 Iterative Application Modernization Pattern & Strangler Pattern 📚

🎯 Deploy Your first Web Application in minutes on Heroku || AWS AppRunner & RDS (Free-Tier 🆓)


## 1. Iterative Application Modernization

Monolith to MicroServices: Many **Monolithic Applications** generate revenue for your company by adding value to your customers. You may have heard statements such as "let's move to a **MicroService-based Architecture**", but "we must deal with the **Data Tier** first". 

> How do we get there safely when we are heavily dependent on the application ⁉️

✅ Martin Fowler’s **[Strangler Pattern](https://www.linkedin.com/posts/nnthanh_migrating-monolithic-applications-with-the-activity-6775946159061127169-XC9h)** 📚: This methodology has been applied to moving specific data sets from a multi-terabyte Monolithic Database to a **Purpose-built Database** (SQL: MySQL / Postgres; NoSQL: MongoDB / DynamoDB), and utilizing a **Data Lake** to improve data access and performance.

   * https://www.linkedin.com/posts/nnthanh_migrating-monolithic-applications-with-the-activity-6775946159061127169-XC9h
   * https://www.slideshare.net/SmartBizVN/migrating-monolithic-applications-with-the-strangler-pattern

> [Example] eCommerce Breaking-down the Monolith (Data-tier and App-tier)

![Iterative Application Modernization Pattern.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1665720524181/7qKcShTFY.gif align="left")

* We have separated Shipping Service Data into a purpose-built database and a MicroService designed to handle shipping. With the newly developed Shipping Service, you will have the opportunity to develop MicroServices that focus on one job and do it extremely well.
* The Orders Service will come next, and Inventory Service will get their own MicroServices.
* Shopping Cart Service remain in the Monolith to ensure that customer service is not disrupted while the application is rearchitected. Once all monolithic capabilities have been replaced by MicroServices, we can now eliminate the monolith-app. Note that both Monoliths and MicroServices will coexist for a period of time.

☑️ Additionally, you may also use **Adapter pattern** and **Façade pattern**.


## 2. 🆓 [Dev/Test] Users < 10,000

- 🥇 Multi-AZ
- 🥇 Elastic Load Balancing between tiers
- 🥇 Auto Scaling
- 🎖️ Service-Oriented Architecture (SOA): Split Tiers into individual SOA Services.


### Lab 1. Hosting Apps on Heroku

> ☑️ TODO: https://heroku.com/deploy?template=https://github.com/OceanSoftIO/ecommerce/

![Hosting-NodeJS-Apps-on-Heroku.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665724324729/SMIu2bJgx.png align="left")

⚠️ Heroku Free-Tier: [Heroku Pricing](https://www.heroku.com/pricing) || [Where Can Heroku Free Tier Users Go?](https://thenewstack.io/where-can-heroku-free-tier-users-go/)

* [Example] This application has the following components:

    ![Hosting-NodeJS-Heroku.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665736466205/5-J4yeZ71.png align="left")

    * Backend: Node.js REST API built with Express.js with resource endpoints that use Client to handle database operations against a PostgreSQL database (e.g., hosted on Heroku).
    * Frontend: Static HTML page to interact with the API.

### Lab 2. Deploy Your first Web Application in minutes

* ☑️ TODO - Build and deploy solutions on AWS using AWS App Runner and Amazon RDS 🆓: https://github.com/OceanSoftIO/Terraform/tree/feature/AppRunner
    
  ![Build and deploy solutions on AWS using AWS App Runner and Amazon RDS](https://cdn.hashnode.com/res/hashnode/image/upload/v1665725359083/e0l2FuVwy.png align="left")


## 3. 🥈 [Staging]  

* 🥈 Serving content smartly (Cloud Storage/S3, CDN/Cloudfront)
* 🥈 Caching off databases
* 🥈 Moving state-off tiers that auto scale

## 4. 🥉 Production 

* 🥉 Monitoring, metrics, and logging: Deeply analyze your entire stack then fine-tuning of your application.

    ![AWS X-Ray - Visualize service call graph.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1665737176210/XqQvPDyd0.gif align="left")

* 🥉 Going from Multi-AZ to Multi-Region
* 🥉 Database: 
    - Federation: Splitting into multiple databases based on function
    - Sharding: Splitting one data set across multiple hosts
    - Moving some functionality to other types of databases (NoSQL, Graph)

    ![Users-1000000.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1665739864518/h52YE_8eH.gif align="left")

## 5. Next Steps ⚡

* 🏅 Service-Oriented Architecture (SOA) of features/functionality

* 🏅Build serverless whenever possible ⚡

    ![The Micro-Services architecture.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1665737346497/bfa1aLMHO.gif align="left")



