Application Overview and Architecture
The voting application is composed of several distinct components:- Voting App: A Python-based web application built with Flask, where users cast their votes.
- Redis: A messaging system that collects the submitted votes.
- Worker: A .NET application (with a Java-like code sample preserved) that processes votes and updates a PostgreSQL database.
- Result App: A Node.js and Express application that retrieves and displays voting results from the database.

The Voting Application
The voting app is a Flask-based Python application found in thevote directory. Its main file, app.py, defines GET and POST routes. The GET route renders the index page for voting, while the POST route captures the vote, connects to Redis, and stores the vote data.
Below is an enhanced excerpt of the Python code with clear descriptions:
votes list.
Dockerfile for the Voting App
The Flask application is containerized using a Dockerfile based on the Python 2.7 Alpine image:
The .NET Worker
The worker component, located in theworker folder, is responsible for processing votes. It retrieves votes from Redis, updates the PostgreSQL database, and logs its activities. Below is an excerpt of the worker code (presented in Java-like syntax for historical reasons):
Dockerfile for the Worker
The Dockerfile for this component uses the Microsoft .NET SDK image. It adds the worker’s source code and publishes the application:
The Result Web Application
The result web application is built using Node.js and Express. It connects to the PostgreSQL database to query and display real-time voting results. Theserver.js file configures the Express server, sets up Socket.IO for live updates, and implements a retry mechanism for establishing a connection to PostgreSQL.
Below is an excerpt from the Node.js application:
Dockerfile for the Result App
The Dockerfile for the result application is based on a slim version of Node.js. It installs required dependencies and starts the Node server:
Deploying the Application
This section outlines how to deploy the system components using Docker.Cloning the Repository
To begin, clone the repository to your local machine:example-voting-app directory.
Building and Running the Voting App
-
Navigate to the
votedirectory and inspect the Dockerfile by running: -
Build the Docker image for the voting app:
-
Verify the image build by listing available Docker images:
-
Launch the voting app container by mapping container port 80 to host port 5000:
redis.rpush('votes', data) call.
Ensure Redis is running and linked correctly before casting votes to avoid connectivity issues.
Deploying Redis
Since the voting app relies on Redis for vote submission, follow these steps:-
Start a Redis container:
-
Re-run the voting app container with a link to the Redis container:
Deploying PostgreSQL and the Worker
The worker component processes votes by interacting with a PostgreSQL database. To deploy these components:-
Remove any existing PostgreSQL container named
db(if present): -
Run a PostgreSQL container (version 9.4):
-
Verify that PostgreSQL is running:
Building and Running the Worker App
-
Change to the
workerdirectory and inspect the Dockerfile: -
Build the worker image:
-
Start the worker container by linking it to both Redis and PostgreSQL:
Deploying the Result App
To deploy the Node.js-based result application and view live voting updates:-
Navigate to the
resultdirectory and review its Dockerfile: -
Build the result app image:
-
Launch the result app container by mapping container port 80 to host port 5001 and linking to PostgreSQL: