This is part 5 of Developing Instagram Clone series, other parts are linked below

  1. Developing Instagram Clone: Introduction.
  2. Developing Instagram Clone: Discovery Service.
  3. Developing Instagram Clone: Auth Service
  4. Developing Instagram Clone: Media Service.
  5. Developing Instagram Clone: Post Service.
  6. Developing Instagram Clone: Graph Service.
  7. Developing Instagram Clone: Newsfeed Service.
  8. Developing Instagram Clone: Gateway Service.
  9. Developing Instagram Clone: Front-end Service

Post service is a straight forward service, it provides a CRUD operations for user posts.

It uses MongoDB as a data store and Apache Kafka as a messaging system.

Post service endpoints

Looking into PostApi controller, you’ll find the following endpoints are exposed.

POST "/posts"  //creates new post

DELETE "/posts/{id}" //deletes post by id
GET "/posts/me" // finds current user posts
GET "/posts/{username}" // find user posts
POST "/posts/in" // find posts by ids

Post service and repository

It is using Spring data MongoDB, all you have to do to provide an interface and the operations (following spring data conventions) and spring will provide the implementations for you.

Nothing fancy here, I think method names are descriptive.

Also, post service is self descriptive, it provides CURD operations for Post object (create, update, delete, … etc). You’ll find it uses PostEventSender to send Kafka messages which I will discuss in the next section.

Messaging (Kafka messages)

It is uses Spring cloud stream, for more info about it, refer to Auth Service.

As you can see, it publishes an event to momentsPostChanged to topic whenever a new post is created, updated or deleted.

We will need to listen to these events to update users’ feed, which we will discuss later in the Feed service.

For kafka configurations, also refer to Auth Service.

#microservices #mongodb #cloud #developer

Microservices In Practice: Developing Instagram Clone —Post Service
6.50 GEEK