Skip to content

filipsnastins/demo-distributed-discounts

Repository files navigation

demo-distributed-discounts

Homework about distributed systems.

More documentation in DOCS.md

Installation

With Docker Compose and Poetry

  • Required software

  • Start the app for development (with auto reload enabled)

    docker compose up
    
  • After application start, database is refreshed with test data from scripts/initial_data.py

    • Available campaign_id - 1 and 2
    • Generated 10'000 discount codes for each campaign.
  • Start the app with gunicorn for concurrency testing (production mode)

    docker compose -f docker-compose.gunicorn.yml up
    
  • (optional) To run auto tests with pytest, additionally install dependencies locally with Poetry

    • Update global Python packages
    python -m pip install -U pip wheel setuptools
    
    • Install dependencies
    poetry install
    
    • Activate Python virtual environment
    poetry shell
    
    • Install pre-commit hooks
    pre-commit install
    

Development and testing

poetry run format/lint/test/test_cov_term/test_cov_html/test_ci
  • Run all hooks at once
poetry run hooks

TODO

  • Documentation
  • How to start the app
  • Presentation
  • Fetch a discount code
    • POST, 201
    • GET 200
    • is_used flag
    • 404 if campaign does not exist
    • Authentication with fake JWT like token
    • Decouple business logic from Flask route
    • SELECT FOR UPDATE SKIP LOCKED for concurrent selects
    • Send callback to the brand that code has been created
  • Generate a discount code. Brand wants to create X number of discount codes
    • Generate job ID and simulate as if job was placed to the queue
    • Create discounts codes asynchronously
    • Route for polling job status <-- not doing now

About

Homework about distributed systems.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published