This project provides a gRPC-based SuperHero service that allows clients to search for superheroes and receive real-time updates about changes to superhero data.
The following diagram illustrates the architecture of the SuperHero Service:
Before running the server and client, ensure the following prerequisites are met:
-
Python:
- Install Python 3.8 or higher.
- Install
pip(Python package manager).
-
Redis:
- Install and run a Redis server locally or use a cloud-hosted Redis instance.
- Default Redis host:
localhost - Default Redis port:
6379
-
Install Dependencies:
- Install the required Python libraries:
pip install -r requirements.txt
- Install the required Python libraries:
-
Environment Variables:
- Create a
.envfile in the project root directory with the following content:ReplaceSUPERHERO_API_KEY=<your_superhero_api_key><your_superhero_api_key>with your actual API key for the SuperHero API.
- Create a
-
Start the Redis Server: Ensure the Redis server is running. You can start it locally with:
redis-server
-
Run the Server: Start the gRPC server by running:
python <your-project-root>/server/superhero_service.py
-
Server Output: The server will start on port
50051and display logs for cache statistics and updates being produced to the message queue.
-
Run the Client: Start the client by running:
python <your-project-root>/client/superhero_client.py
-
Client Output: The client will:
- Subscribe to updates from the message queue.
- Search for a superhero (e.g., "Batman") and display the results.
- Continuously display real-time updates for superheroes.
- Start the Redis server.
- Run the server in one terminal.
- Run the client in another terminal.
- Observe the client receiving real-time updates from the server.
<your-project-root>
├── client/
│ ├── superhero_client.py # Client implementation
├── components/
│ ├── message_queue.py # Redis-backed message queue
├── server/
│ ├── api_client.py # SuperHero API client
│ ├── cache.py # In-memory cache with expiration
│ ├── superhero_service.py # gRPC server implementation
├── vendor/
│ ├── superhero_pb2.py # gRPC protobuf definitions
│ ├── superhero_pb2_grpc.py # gRPC service stubs
├── .env # Environment variables
├── requirements.txt # Python dependencies
├── Architecture.png # Architecture diagram
└── readme.md # Project documentation
- Ensure the
.envfile is properly configured with your SuperHero API key. - The Redis server must be running for the message queue to function.
- The server and client communicate via gRPC on port
50051.
