Skip to content

RESTful API build with FastAPI - scope: transactions & user interactions

License

Notifications You must be signed in to change notification settings

geraldelorm/fido-transaction-api

Repository files navigation

Fido Transactions API

RESTful API built with FastAPI - scope: transactions & user interactions

Setup and Run Instructions

Prerequisites

  • Python 3.10+
  • pip
  • Virtualenv
  • Docker

Setup Steps

  1. Clone the repository:

    git clone <repository-url>
    cd fido-transaction-api
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Create a .env file refer to .evn.example:

    touch .evn
  4. Install dependencies from the requirements.txt file:

    pip install -r requirements.txt
  5. Run docker compose:

    docker compose up --build
  6. API should be running on:

    http://0.0.0.0:8000 # http://localhost:8000/

Design and Architectural Decisions

1. API Design

  • RESTful API: The API follows REST principles, making it intuitive and easy to use.

  • Status Codes: Proper HTTP status codes are used to indicate the result of an API request (e.g., 200 for success, 404 for not found, 500 for server error).

2. Models

  • Pydantic Models: Used Pydantic models for data validation and serialization. This ensures that the data conforms to the expected schema before processing.

3. Database Connections

  • MongoDB: Utilized MongoDB for its flexibility and scalability.

4. Caching

  • Redis: Integrated Redis for caching frequently accessed data to reduce database load and improve response times. Implemented strategies of cache updates and invalidation.

5. Error Handling

6. Logging

  • Loguru: Used Loguru for logging, providing better insights into the application's behavior and aiding in debugging.

7. Background Tasks

  • FastAPI Background Tasks: Utilized FastAPI's background tasks to handle operations that do not need to block the main request-response cycle.

8. Scheduler

  • Analytics Computation Scheduler: Implemented a scheduler to periodically compute and store analytics data.

9. Configuration Management

  • Environment Variables: Managed configuration using environment variables to keep sensitive information secure and make the application configurable.

Strategies for Scaling to a Substantial User Base

1. Pagination of Endpoints

  • Strategy: Implement pagination for endpoints that return large datasets.
  • Trade-offs:
    • Pros: Reduces server load and improves response times.
    • Cons: Adds complexity to the API and client-side code.

2. Database Indexing

  • Strategy: Use indexing on frequently queried fields to speed up database operations.
  • Trade-offs:
    • Pros: Significantly improves query performance.
    • Cons: Increases storage requirements and can slow down write operations.

3. Event-Driven Architecture

  • Strategy: Implement an event-driven architecture to decouple services and handle asynchronous tasks.
  • Trade-offs:
    • Pros: Improves scalability and fault tolerance.
    • Cons: Adds complexity to the system and requires robust event management.

4. Comprehensive Testing

  • Strategy: Increase the scope of testing to include integration, performance, and stress tests.
  • Trade-offs:
    • Pros: Ensures the reliability and performance of the application under various conditions.
    • Cons: Requires more resources and time to implement and maintain.

5. Resilient Deployment Strategies

  • Strategy: Use Kubernetes (K8s) for resilient and scalable deployments.
  • Trade-offs:
    • Pros: Provides automated scaling, self-healing, and efficient resource management.
    • Cons: Adds complexity to the deployment process and requires expertise in Kubernetes.

Thank you!!

About

RESTful API build with FastAPI - scope: transactions & user interactions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published