A modern, real-time polling and voting application built using Next.js (frontend) and FastAPI (backend) — powered by Redis Pub/Sub and Server-Sent Events (SSE) for instant updates.
This project demonstrates a microservice-oriented architecture that blends frontend reactivity, backend scalability, and real-time communication.
Votely allows users to create, vote, and interact with polls in real time.
Whenever a user votes, every connected client automatically receives updated results — no refresh required.
You’ll build the frontend while integrating with backend microservices (PollService, AuthService).
+-------------------+ +-------------------+ | Next.js Frontend| <-----> | API Gateway | | (Votely Client) | | (Simulated Layer)| +-------------------+ +-------------------+ | | | | v v +-------------------+ +-------------------+ | PollService | | AuthService | | FastAPI + Redis | | Spring Boot | | PostgreSQL DB | | JWT Auth / MQ | +-------------------+ +-------------------+
| Layer | Technology |
|---|---|
| Frontend | Next.js (App Router), TypeScript, Tailwind CSS, shadcn/ui |
| Backend (PollService) | FastAPI, PostgreSQL, Redis (Pub/Sub), asyncio |
| Auth Service | Spring Boot, Redis, RabbitMQ |
| Real-Time Updates | Server-Sent Events (SSE) via Redis Pub/Sub |
| Deployment (Optional) | Docker Compose (Redis + API + Frontend) |
Each poll has a unique Redis Pub/Sub channel (e.g., poll_<poll_id>).
When a vote occurs:
- FastAPI publishes the updated poll data to Redis.
- SSE stream connected to that poll receives the update.
- Frontend updates instantly — no reload required.
- Registered Users → Authenticated via JWT token from AuthService.
- Guest Users → Identified by a unique
deviceIdstored inlocalStorageor cookies.
All API interactions (both PollService and AuthService) are routed through a central module in /lib/api.
Handles:
- Base URL management
- Token injection (JWT/deviceId)
- Error handling & response parsing
Displays a list of all active public polls with:
- Poll title
- Description snippet
- “View Poll” button
Use shadcn/ui Cards for a clean layout.
Displays:
- Poll title and options
- Vote buttons (disabled if already voted)
- Real-time results (progress bar + percentages)
- Like (❤️) functionality
After voting:
- The poll locks for the user
- Results update instantly using SSE
- The frontend opens an EventSource stream to
/poll/{pollId}/events. - When any user votes, the backend publishes via Redis → all clients update.
Form includes:
- Poll Title / Question
- 2–5 dynamic option fields
- Submit button (calls
PollService)
This guide will help you set up and run the Votely project locally, including both the frontend (Next.js) and backend (FastAPI) with Redis for real-time updates.
Before you start, make sure you have these installed:
git clone https://github.com/kbpramod3/votely.git
cd votely
🧠 2. Setup Backend (FastAPI + Redis)
Option 1: Run with Docker (Recommended)
```bash
git clone https://github.com/kbpramod3/pollservice.git
cd pollservice
docker-compose up -d redis postgres
Then configure .env for your FastAPI backend:
This will start:
Redis (for Pub/Sub real-time communication)
PostgreSQL (for poll data storage)
⚙️ 3. Install and Run Backend
cd backend
pip install -r requirements.txt
uvicorn main:app --reload
Your FastAPI server should now be running at:
http://localhost:8000