Infrastructure - FEUP-MEIC-DS-2025-26/madeinportugal.store GitHub Wiki
Cloud Infrastructure
[!WARNING] This page is still in progress. Expect breaking changes.
In this page, all the details about the event-driven micro-architecture deployed will be documented.
See the ToC below to find what you need:
Table of Contents
How to integrate?
See below a list of high-level actions needed to integrate your services to the production architecture. Depending on your needs, you may not need to have a microfrontend or a microservice.
Frontend
-
Make sure to have a microfrontend running in a Google Cloud project.
See the example in the PoC for a starting point. -
Make sure that in production, all of the API calls are made to the gateway URL (api.madeinportugal.store).
-
Add your microfrontend provider URL to the host and apply the components inside routes.
See the repository MIPS-Frontend-Host-Module-Federation for more detailed instructions.
Middleware / Gateway connection
-
Make sure to have a microservice running in a Google Cloud project.
See the Terraform template as a starting point on how to deploy a Docker image to the cloud. -
Add your route to the Gateway's list.
See the MIPS-Gateway-Routes repository for more detailed instructions. -
Make sure your deployment of the microservice is only accessible via the gateway and that is not open to the internet. See the MIPS-Gateway repository for the service account and the settings to change in your Cloud Run instance.
Backend / Pub/Sub connection
-
Authenticate your microservice to get access to the production Pub/Sub.
Get the service account credentials in this Microsoft Teams post available in the DevStack channel. -
Create the topics and subscriptions needed for your service.
See the MIPS-PubSub repository for more detailed instructions.
Prerequisites
These requisites are only necessary until the final delivery; it is okay if they are not met for now.
- All of the microservices cannot be in the same project, due to the limited credits a single account has;
- All microservices should be isolated from the internet as much as possible (except the user-facing ones);
- All microservices should know at the build step the domains of the components used to make communication between microservices possible;
- Avoid single points of failure, which can make the whole product go down.
Overview
[!NOTE] See the C4 diagram for a more updated diagram.
- When a user asks for a page from madeinportugal.store, the request goes to the "root" micro-frontend;
- The "root" micro-frontend, depending on the page, is programmed to request components from other micro-frontends as needed;
- When a micro-frontend needs data from its backend, a request is made to the gateway, specifying the request itself and which microservice should be contacted;
- Each request to the gateway is responded to by the gateway with the content of the answer given by the microservice;
- When a micro-frontend wants to do an action to a different microservice, it should request its backend via a REST API to ask for that action via the Google Pub/Sub; When that microservice is available, it sends the response to the Pub/Sub, which is later read by the backend;
- Each microservice is also responsible for listening to subscribed messages and for sending state changes of their own context in a way that is useful for other microservices; the Google Pub/Sub is the intermediary of this event-driven communication.
Frontend: Micro-frontend
// TODO
Middleware: Gateway
// TODO
Backend: Pub/Sub
// TODO
Q&A
-
Q: The microservices need to have access to the singular Google Pub/Sub/Gateway/"root" micro-frontend while still being isolated from the network.
Looks like a Google Pub/Sub instance can be configured to accept filtered IPs, but that needs to be explored further. Creating a virtual network between all the microservices can be another option. -
Q: A micro-frontend needs to know a URI that it can use to make API requests.
The gateway could also have a custom domain, like api.madeinportugal.store, for example. -
Q: How can the gateway know to which microservice to send a message from the request received alone?
There are many ways to do this. One way can be encoding in the path URL; for example all APIs about the product microservice can be in the URL api.madeinportugal.store/product. -
Q: If a component used to make communication between microservices possible goes down, the whole service is impacted; how to avoid that?
Those components could be replicated, for example. -
Q: How can the backend tell the frontend that an operation involving other microservices was unsuccessful if all requests go through the Pub/Sub and are, therefore, asynchronous?
The frontend can listen for requests from the backend with React Hooks, for example.
More resources
- Google Pub/Sub Emulator
- Micro-frontend PoC
- Google tutorial on how to integrate Google Pub/Sub with Google Cloud Run
Feel free to message any of the authors with more questions, needs of clarification or suggestions! 👋
Special thanks to:
- Prof. Filipe Figueiredo Correia for the architecture design;
- Gustavo Poção Mateus for the micro-frontend implementation;
- Eduardo Castro Portugal Ferreira for the gateway implementation;
- Rubem Viscard Neto for the Pub/Sub emulator;
- Henrique Sardo Fernandes and the devCoPs team for the deployment help;
- José Carlos Malheiro de Sousa and Nuno Simão Nunes Rios for sharing their experience with Google Pub/Sub.