Whenever you start designing a service or putting it together, it is worth thinking very critically about exactly what your services want to do.
- The goal of post service
| path | method | body? | goal |
|---|---|---|---|
| /posts/ | POST | {title:string} | create a new post |
| /posts/ | GET | - | retriew all the posts |
- The goal of comment service
| path | method | body? | goal |
|---|---|---|---|
| /posts/:id/comments | POST | {content:string} | create a new post |
| /posts/:id/comments | GET | comment[] | retriew all the posts |
- Import a Query service Posts
- the data schema for query service
id title comments he23 Yes [] - Event format for query service
- the data schema for query service
type PostEvent = {
type: "PostCreated" | "PostDeleted";
data: { id: string; title?: string };
};
type CommentEvent = {
type: 'CommentCreated" | "CommentDeleted" | "CommentUpdated",
data: {commentId:string, postId?:string}
}-
Solutions for adding a moderation service
-
Option One: send comment event from moderation to query service
- cons: what if the moderation operation handled by a human?
-
Option Two: send the comment both to the moderation service and query service.
- cons
- There could be many event sources for comment
- We are requiring a presentation services to have a deeper understanding of logic
- cons
-
Option three: make the comment to handle comments related business logic handling
- Domain related event
- Generic event
- pros
- the query service only care about update event, compared with caring about a bunch of events
-
Notice here, the comment service keeps the full data of comments, we have a palce that stores the integral comment data.
-
handle services down time or services brought in the future
-
Sync request
-
Directly database access(what if post and comment services using different type database, we will bring query handling inside the query service)
-
Store Event(real world solution) at the event-bus service
-
