Lighthouse Scanner: From Monolith to Microservices

Service 1: Static Webpage

FROM nginx:1.19.0
COPY ./src/dist /usr/share/nginx/html
COPY ./conf/default.conf /etc/nginx/conf.d/default.conf
COPY ./conf/nginx.conf /etc/nginx/nginx.conf

Service 2: API

  • Remove the delivery of the webpage code
  • Remove all functions for executing scan requests
  • Simplify health check to return just an HTTP 200 for the main process.
FROM node:lts-alpine3.11
WORKDIR /etc/lighthouse-api
COPY package.json .
RUN npm i
COPY app.js .
COPY src/ ./src
ENTRYPOINT ["/usr/local/bin/node"]
CMD ["app.js"]

Service 3: Worker

  • Before spawning a scan process, execute a ping to validate that the domain exists
  • The worker has a counter for the number of concurrent scan requests, it can only handle 3 scans at the same time and will deny each new request
  • After scanning, clean up all forked child processes
FROM node:lts-alpine3.11
WORKDIR /etc/lighthouse-scanner
COPY /package.json .
RUN npm i
COPY /app.js .
COPY /src/ ./src
ENTRYPOINT ["/usr/local/bin/node"]
CMD ["app.js"]

The final architecture

Do You Need Microservice in Small Teams?




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store