This chapter delves into the creation of a cloud native, event-driven microservice: the profile service. This profile service will build and continuously update user profiles based on changing facts from the fact service. The architecture will employ Google Pub/Sub for event notifications, Firestore as a serverless database to store user profiles, and Cloud Run for hosting the service.
Note
The code for this chapter is in the profile-service folder of the GitHub repository.
Requirements
Let’s go straight into the requirements.
User Story
Figure 8-1 is the user story you will be focusing on.
Figure 8-1. Project 4 user story
Elaborated Requirements
It is safe to assume that the system has many users and most are not going to make frequent changes to their skills. This means it is more likely for there to be a request for a profile than for facts to be edited.
You can take advantage of this by storing the profile indefinitely once it’s generated and only updating it when a change is made to the facts. This has the advantage of not needing to access the PostgreSQL database every time a profile is requested, meaning you can keep the instance size small and reduce the cost of the facts service.
Therefore, the requirements are as follows:
- The service should be triggered every time there’s a change in the user facts stored in the fact service.
- The service should generate a user profile as a single JSON document that can be stored and later retrieved on demand.
- Since the profile service is triggered by fact changes and does not require an immediate response to the caller, it can operate asynchronously.
- The service must be able to scale to meet the demands of the system, managing large numbers of profile requests and updates.
- The service should be designed for high availability, ensuring that it’s always ready to respond to change notifications and serve profiles.
- The service should be low cost and require minimal maintenance, leveraging serverless technology to minimize the need for server management and capacity planning.
By designing the service to meet these requirements, you can ensure it will efficiently and reliably manage user profiles, providing up-to-date information for users to share. The remainder of this chapter will guide you through how to build and deploy a service that fulfills these needs.
Solution
Again, it is possible to produce a low-cost solution to these requirements using Google Cloud Services.
Summary of Services
To build the profile service that meets these requirements, you are going to make use of a few key Google Cloud services. Let’s take a closer look at each of them.