A simple social media service platform with micro service architecture contains following services:
- Authentication and user management service
- Post Service
- User Interaction Service
- Moderation and Analysis Service
- User Engagement Service
This repository is structured as a mono repo for all micro services mentioned above.
Every service is located in a folder suffixed with the name <SERVICE_NAME>-service
No module is shared between any two services. Every service is almost containing the similar structure. And the common service structure is following:
|service1-root-folder
|--main.py
|--settings.py
|--pyproject.toml
|--requirements.in
|--requirements.txt
|--Dockerfile
|--docker-compose.yaml
|--apps
|--migrations
|--core
|--__init__.py
|--databases.py
|--enums.py
|--mail.py
|--models.py
|--redis.py
|--security.py
|--tests.py
|__app1
|--__init__.py
|--models.py
|--schemas.py
|--signals.py
|--views.py
|--schedulers.py
|--tests.py
|--events
|--__init__.py
|--consumers.py
|--processors.py
|--producers.py
|--app2
|.......
|.......
|--appN
|service-2-root-folder
|service-3-root-folder
|service-4-root-folder
|service-5-root-folder
- Language: Python version 3.10
- Framework: FastAPI
- Database: Postgres
- Database ORM: Tortoise-orm (Fully Async)
- Cache Server: Redis
- Message Broker: Redis
- Server: uvicorn
- Scheduler: Python scheduler
To fire up the microservices you need to execute following commands from the root of the project:
docker compose -f docker-compose-local.yaml up --build
Starting up the servers you'll get following services running on different ports and their swagger docs can be found visiting following:
- Authentication service (http://0.0.0.0:8000/docs)
- Post service (http://0.0.0.0:8001/docs)
- Interaction service (http://0.0.0.0:8002/docs)
- Moderation service (http://0.0.0.0:8003/docs)
- Engagement service (http://0.0.0.0:8004/docs)
- Sign up
- Sign in
- Profile update
- Profile detail
- User connect and disconnect
- User connection lists
- Change Password
- Token Verify
- Post create
- Post lists
- Post update
- Post delete
- Comment add
- Comment update
- Comment delete
- Comment detail
- Reaction add
- Reaction delete
- Post view
- User Activity Profile
Currently it has no visible functionality. All it is containing is bussiness logic related functionality
Need user registration to add users into the system from the authentication service. Then users can obtain token from the login endpoint. After that they need to create Post using the post service. Then authenticated users can use user interaction endpoints to comment, react and view posts. Users can connect other users from authentication service. Authenticated users can also see their activity profile from the user engagement service.
We've used asynchronous event streaming to communicate between services. But to authenticate for all api endpoints we've used token verification from authentication service.
Services are producing and consuming different events independently from different micro services. Then whoever is interested on those events listens and takes actions according to that.
Here we've used redis group messaging instead of Pubsub as we wanted to ensure services who are interested to certain events can get the message atleast once even if they were down for a certain duration. As soon as they are live, they'll get the last checkpoint from where they didn't listen any new events.
As these services need continuous and real time events, so we implemented our event consumers to listen events continously by running event listeners as cron jobs. Event producers are connected on demand when they need to fire event message using the Redis client.
All the endpoints and database connections of these services are fully asynchronous to reduce waiting times for others.
There are lots of missing pieces for these microservices. Some of the vitals are as following:
- We're missing the API gateway service to serve and secure all the available microservices efficiently.
- Unit and integration tests are missing for all the services due to lack of allocated time
- Linting, type checking and code quality related tests are not ensured
- Package upgrade and management is not automatic
- Although it is a social media service related application, still it is missing file handling or use of files.
- Content analysis is faked with a random function that randomly choose a post or comment and take moderation actions like delelting the content. This should be replaced with a real content analysis functionality.
- NFT model is genrated for posts with the status
POSTED
. And we've generated and saved the information for the blockhcain to mint it as aERC1155
NFT. - We're generating NFT data for Post and Post Comments' information as
data
inPostNFT
andCommentNFT
model but we're missing functionality for uploading it on anyIPFS
service and only then we'll gettokenUri
for theERC1155
token.tokenUri
will be the only unique aattribute for these NFTs saved in blockchain. - We're missing Service interface to integrate these microservices with blockchain.
- User recommendation service is not integrated with existing services.
- Needs to implement more fine tuned business logic to make features more smoother.
- Notification frameworks like - Firebase or Apple notification could be used to notify users instantly on devices.