DEV Community

Ameh Mathias Ejeh
Ameh Mathias Ejeh

Posted on

Containerized Sports API Management System

Overview

The Containerized Sports API is a lightweight and efficient sports data API designed to provide real-time and historical game information, player stats, and league details. The API is containerized using Docker, ensuring seamless deployment and scalability across various environments.

Objective

The project aims to simplify the integration of sports data into applications by providing a reliable and scalable API for developers. It can be used in fantasy sports apps, game-day alerts, dashboards, or any system requiring sports data.

Features

  • Real-Time Sports Data: Fetch live game updates and scores.
  • Containerization: Fully containerized using Docker for ease of deployment.
  • RESTful Design: Clean and well-structured endpoints for ease of use.

Architecture

The project follows a microservices architecture with the following components:

  • Backend: A Python-based RESTful API built with Flask or FastAPI.
  • Containerization: Docker is used to package the application and its dependencies.
  • Data Source: Integration with third-party sports APIs for live and historical data.

Architecture Drawing

Image description

Prerequisites

Before running the project, ensure you have the following installed:

  • AWS Account
  • Sport-API-Key from serpapi.com
  • Docker CLI and Desktop Installed.
  • Serpapi library in local environment
  • Python 3.8 or later.
  • Git.

Setup Instruction

Clone the Repository

git clone https://github.com/ameh0429/containerized-sport-api.git
cd containerized-sport-api

Enter fullscreen mode Exit fullscreen mode

Create ECR Repo

aws ecr create-repository --repository-name sports-api --region us-east-1
Enter fullscreen mode Exit fullscreen mode

Image description

Authenticate and Build the Docker Image

aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com

docker build --platform linux/amd64 -t sports-api 
Enter fullscreen mode Exit fullscreen mode

Image description

Tag and push the docker image to the ECR Repo

docker tag sports-api:latest <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest
docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/sports-api:sports-api-latest
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Set Up ECS Cluster with Fargate

Create an ECS Cluster

  • Name the Cluster (sports-api-cluster1)
  • For Infrastructure, select Fargate.

Image description

Create a Task Definition:

  • Name the task definition (sports-api-task)
  • For Infrastructure, select Fargate
  • Add the container
  • Define environment variable.

Image description

Run the Service with an ALB

  • Capacity provider: Fargate
  • Select Deployment configuration family (sports-api-task)
  • Name the service (sports-api-service)
  • Desired tasks: 2
  • Networking: Create new security group
  • Load Balancing: Select Application Load Balancer (ALB).

Image description

Test the ALB:

  • After deploying the ECS service, note the DNS name of the ALB (e.g., sports-api-alb-<AWS_ACCOUNT_ID>.us-east-1.elb.amazonaws.com)
  • Confirm the API is accessible by visiting the ALB DNS name in your browser and adding /sports at end

Image description

Configure API Gateway

Create a New REST API:

  • Name the API (e.g., Sports API Gateway)

Set Up Integration:

  • Create a resource /sports
  • Create a GET method
  • Choose HTTP Proxy as the integration type
  • Enter the DNS name of the ALB that includes /sports (e.g. http://sports-api-alb-<AWS_ACCOUNT_ID>.us-east 1.elb.amazonaws.com/sports

Deploy the API:

  • Deploy the API to a stage (e.g., dev)
  • Note the endpoint URL

Image description

Test the System

  • Use a browser to test:
https://<api-gateway-id>.execute-api.us-east-1.amazonaws.com/prod/sports
Enter fullscreen mode Exit fullscreen mode

Image description

What we Learn

  • Leveraging Docker simplified application deployment and ensured consistency across development, testing, and production environments.
  • Designing a scalable and maintainable REST API highlighted best practices, including versioning, error handling, and proper status code usage.
  • Utilizing asynchronous programming (e.g., with Python) improved API performance by handling multiple requests efficiently.

Future Enhancements

  • Integrate additional sports leagues and events (e.g. MLB, FIFA) to make the API more comprehensive and cater to a wider audience.
  • Introduce a caching layer using tools like Redis or Memcached to improve API response times and reduce server load for frequently accessed data.
  • Build a companion mobile application to provide push notifications and an interactive interface for users to access real-time data on the go.

Top comments (0)