Skip to main content
in France
Français

Breezy

CESI project · TypeScript, Node.js, Next.js

A Twitter-style social network split into six microservices, built by four of us over four weeks for a CESI course.

At CESI, courses are taught in blocks of a few weeks on a single subject, and each block ends with a group project to hand in. Breezy was the project for the distributed applications block, which lasted four weeks. We had to build a Twitter-style social network with posts, follows, likes, private messages and real-time notifications, all split into microservices.

I was the project lead. On top of coordinating the team, I built authentication, profiles, the feed and push notifications, and I handled the deployment.

Splitting into services

We made six services, one for authentication, one for profiles, and the others for posts, media, messages and notifications. Each service has its own database, and the others never access it directly. They go through its API instead.

The brief required us to use both PostgreSQL and MongoDB, so we had to decide which database went where. We used PostgreSQL wherever we needed relations, so for authentication and profiles, since follows link users to each other. Posts, messages and media live in MongoDB, because its schema is far more flexible and it copes better with large volumes of data.

HTTPpublishmetrics, logs, tracesWebSocket, SSE, Web PushWeb clientNext.jsNginx gatewaySix servicesgRPC between them, one DB eachRabbitMQeventsObservabilityPrometheus, Grafana, Loki, Jaeger
Six Node.js services, each with its own database, behind an Nginx gateway. Live updates go back to the client over WebSocket, SSE or Web Push.

How services talk to each other

For every exchange between two services, we had to decide whether the caller needed an answer straight away or not.

When it does, we use gRPC. For example, to show a user’s feed, the post service needs to know who that user follows. So it asks the profile service and waits for the answer before going any further.

Everything else goes through RabbitMQ. When someone likes a post, the post service publishes an event and carries on without waiting. The notification service reads that event and sends the notification, by email, live or as a Web Push. If the notification service crashes, the rest of the app keeps working, and the events stay in the queue until it restarts.

The gateway

Every request comes in through an Nginx gateway. For protected routes, Nginx first asks the authentication service whether the token is valid. If it is, it forwards the request to the right service, with the user’s role in a header. So the services don’t each have to check it again.

We also set a lower rate limit on sign-in and sign-up than on the rest of the API, to cut down on brute-force attempts.

While preparing the production deployment, we noticed that RabbitMQ’s port could be reached from outside, because of a mistake in the Docker configuration. We fixed it, but I don’t think we would have spotted it without deploying.

Logs, metrics and traces

With six services, when something broke, we didn’t always know which one was at fault. So we set up OpenTelemetry to follow each request from one service to the next. In Jaeger, you can see the path a request took and how long it spent in each service. Logs go to Loki, metrics to Prometheus, and we look at all of it in Grafana.

Setting it up took us a while. Before that, tracking down a bug meant reading each service’s logs one by one.

Looking back

For a project this size, I think microservices cost us more than they gave us. We spent a lot of time on communication between services, deployment and monitoring, and less on the features themselves. That was the point of the course, so I don’t regret it, and I learned a lot.

But if I had to build an app like this for real, I’d start with a single backend split into modules, and only pull a service out when there’s a specific need for it. That’s the approach I took for Pathpipe.

at a glance

  • ContextCESI project, distributed applications course
  • RoleProject lead, developer and deployment
  • TeamFour people, four weeks
  • StackTypeScript, Node.js, Next.js, gRPC, RabbitMQ, PostgreSQL, MongoDB, Redis
  • OpsNginx, Docker, Prometheus, Grafana, Loki, OpenTelemetry, Jaeger
  • LinksView code