skip to Main Content

I have a spring-boot application named ‘RestAPI‘ which acts as backend service for my UI.
The RestAPI has become a bit complex… so I need to break it down in microservices.

The RestAPI has following functionalities I would like to convert to microservices:

  1. Service 1 – Service for basic operations of Protocol 1.
  2. Service 2 – Service for basic operations of Protocol 2.
  3. Service 3 – Service for complex operations of Protocol 1.
  4. Service 4 – Service for complex operations of Protocol 2.

Note – Just a thought… not finalized if I will follow the above mentioned steps.
But need microservices that is final.

The main question is…
Currently I am using 1 docker container for the RestAPI application.
So.. if I break the RestAPI into microservices will it be a good approach to run all the microservices in one docker container ?

If yes.. how can I achieve it using 1 Docker file or multiple Docker files ?

If no.. why is it not feasible ?

2

Answers


  1. Microservices offer several advantages, such as agility, flexible scaling, continuous deployment, maintainability, testability, independent deployability, technology flexibility, and high reliability. They promote agile ways of working, enabling teams to experiment with new features and allowing for fast and easy independent deployment of individual features. Additionally, microservices provide technology flexibility, high reliability, and increase team autonomy.

    However, if all microservices run in the same container, they will use the same resources, which can result in something like a monolithic application. To avoid this, each microservice must have its own CPU, memory resources, database, storage, etc. While it is possible to run multiple microservices in the same container, it is not recommended.

    To manage each microservice independently, each one should have its own Docker container, which can be orchestrated using Docker Compose or Kubernetes. To achieve this, a Dockerfile must be created for each microservice. The services can also be deployed on AWS Lambda, GCP Cloud Run, App Engine, and other platforms.

    Microservice vs Monolith
    Source: https://mintymint.net/blog/tech/microservices-vs-monolithic-software-architecture-guide/

    Here is some more useful information:

    Login or Signup to reply.
  2. besides the Advantage, if you are curious to run all your Service In One Container.
    FYI:- Not Advisable to use in PROD

    COPY start.sh /apps/start.sh
    RUN  chmod 755 /apps/start.sh
    COPY path/target/service1.jar /apps/project1/service1.jar
    COPY path/target/service2.jar /apps/project2/service2.jar
    COPY path/target/service3.jar /apps/project3/service3.jar
    COPY path/target/service4.jar /apps/project4/service4.jar
    COPY path/target/service5.jar /apps/project5/service5.jar
    
    
    EXPOSE 8080
    CMD ["/bin/bash", "/apps/start.sh"]
    

    Start.sh

    nohup java -jar -Xms2G -Xmx2G -Dspring.profiles.active=${ENVIRONMENT} /apps/project1/service1.jar > service1.log &
    nohup java -jar -Xms2G -Xmx2G -Dspring.profiles.active=${ENVIRONMENT} /apps/project2/service2.jar > service2.log &
    nohup java -jar -Xms2G -Xmx2G -Dspring.profiles.active=${ENVIRONMENT} /apps/project3/service3.jar > service3.log &
    nohup java -jar -Xms2G -Xmx2G -Dspring.profiles.active=${ENVIRONMENT} /apps/project4/service4.jar > service4.log &
    nohup java -jar -Xms2G -Xmx2G -Dspring.profiles.active=${ENVIRONMENT} /apps/project5/service5.jar > service5.log &
    
    make sure to run httpd proxy to direct the calls to right MS
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search