Skip to content

rohanmrb/Microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Breaking down monoliths 🪨⛏️

Convert a monolith architecture based docker-compose application into a microservices based architecture.

Team

Rohan M
Rushab

Requirements:

  • docker and docker-compose. Follow the guides based on your operating system.
  • Internet. Pull docker image python:3.8-alpine beforehand to avoid connectivity issues.

Directory structure for monolithic architecture

├── README.md
├── docs
│   └── <documentation related images/files>
├── microservices
│   ├── Docker-compose.yaml
│   ├── landing
│   │   ├── app
│   │   │   ├── app.py
│   │   │   ├── requirements.txt
│   │   │   └── templates
│   │   │       └── index.html
│   │   └── Dockerfile
│   │

Monolith architecture diagram

Build & Run

# under the microservices directory
docker-compose -f Docker-compose.yaml up --build
access the html page in localhost:5050

To stop the services in detached mode

docker-compose down

Project

  1. Docker File

    • Dockerfiles help building images using a given set of instructions. You can learn about the basics of Dockerfiles here. Use this document to understand the meaning of certain keywords used by Dockerfiles.

  2. Error Handling

    2.1 Variable type of the incoming values from index.html

    • By default, Python considers all input as string. The types are checked in the app.py of every microservice
    • Fix the type of the two variable values received from index.html

    2.2 Handling the None type exception

    • Avoid the crash by handling the exceptions raised in the landing-service app.

  3. Breaking the monolith architecture

    2.0. Decoupling the arithmetic functions.

    • The four arithmetic functions if they reside under landing-service and the landing-service were to become unavailable for whatever reason, the four functions would be unavailable as well.
    • The Docker-compose.yaml is updated to recognize the flask applications as separate services. The Docker-compose.yaml defines the port number and network alias that will be used by landing-service to communicate within the entire architecture

    2.1. Adding more services

    • add: Takes two numbers as arguments and returns their sum
    • subtract: Takes two numbers as arguments and returns their difference
    • multiply: Takes two numbers as arguments and returns their product
    • division: Takes two numbers as arguments and returns their quotient
    • gcd: Takes two numbers as arguments and returns their Greatest Common Divisor
    • lcm: Takes two numbers as arguments and returns their Least Common Multiple
    • modulus: Returns the remainder of two numbers after division. Reference
    • exponent: Returns the result of the arithmetic operation ab
    • greater_than: Return True if the first value is greater than the second else False
    • less_than: return True if the first value is less than the second else False
    • equal: return True if the first value is equal to the second else False

Microservices-based architecture diagram after decomposition

Directory structure of arithmetic microservices:

├── <name of the service>
│   ├── Dockerfile           # same as landing/Dockerfile
│   ├── app
│   │   ├── app.py           
│   │   └── requirements.txt 
│   │  

About

Converting a monolith architecture based docker-compose application into a microservices based architecture.

Topics

Resources

Stars

Watchers

Forks

Contributors