{"id":15063585,"url":"https://github.com/solobarine/lorcan_bet_async","last_synced_at":"2026-01-03T05:02:49.929Z","repository":{"id":257149483,"uuid":"857452836","full_name":"Solobarine/lorcan_bet_async","owner":"Solobarine","description":"An Inventory management platform","archived":false,"fork":false,"pushed_at":"2024-09-14T17:44:30.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-22T06:26:43.607Z","etag":null,"topics":["api","elixir","phoenix","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Solobarine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-14T17:41:16.000Z","updated_at":"2024-09-14T17:44:33.000Z","dependencies_parsed_at":"2024-09-15T03:24:02.902Z","dependency_job_id":null,"html_url":"https://github.com/Solobarine/lorcan_bet_async","commit_stats":null,"previous_names":["solobarine/lorcan_bet_async"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solobarine%2Florcan_bet_async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solobarine%2Florcan_bet_async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solobarine%2Florcan_bet_async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Solobarine%2Florcan_bet_async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Solobarine","download_url":"https://codeload.github.com/Solobarine/lorcan_bet_async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243762120,"owners_count":20343972,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","elixir","phoenix","postgresql"],"created_at":"2024-09-25T00:04:39.279Z","updated_at":"2026-01-03T05:02:49.856Z","avatar_url":"https://github.com/Solobarine.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Inventory and Order Management Microservice\n\nThis microservice is built using Phoenix and provides a RESTful API for managing products, inventory, and orders. It supports asynchronous order processing, ensuring distributed consistency and handling of concurrent inventory updates. The system is resilient with retry mechanisms and failure handling in order processing.\n\n## Features\n1. **Product Management**: \n    - Create, update, and delete products.\n2. **Inventory Management**: \n    - Manage product inventory levels, handle concurrent inventory updates, and ensure data integrity.\n3. **Order Processing**: \n    - Asynchronous order handling.\n    - Ensures that each order is processed only once.\n    - Includes failure handling and retry mechanisms.\n4. **Distributed Consistency**: \n    - Ensures eventual consistency across systems, especially in the presence of asynchronous payments and order processing.\n5. **Database Migration**: \n    - Safely introduces product categories without downtime or breaking changes.\n6. **Resiliency in Async Systems**: \n    - Implements retry mechanisms and failure handling in the order processing system.\n\n## Tech Stack\n- **Phoenix Framework**: Backend framework.\n- **PostgreSQL**: Database for storing products, orders, inventory, and order logs.\n- **Oban**: For asynchronous background job processing (used for handling orders and retries).\n- **Ecto**: Database wrapper and query generator for Elixir.\n\n## Requirements\n- Elixir 1.17.1 (managed with `asdf`)\n- PostgreSQL\n- Phoenix Framework\n- Oban for background jobs\n\n## Setup Instructions\n\n### 1. Clone the Repository\n```bash\ngit clone https://github.com/Solobarine/lorcan_bet_async\ncd lorcan_bet_async\n```\n\n### 2. Install Dependencies\n```bash\nmix deps.get\n```\n\n### 3. Setup the Database\nMake sure PostgreSQL is running, and create and migrate the database.\n```bash\nmix ecto.create\nmix ecto.migrate\n```\n\nTo reset the database, you can use:\n```bash\nmix ecto.reset\n```\n\n### 4. Running the Application\nTo start your Phoenix server:\n\n```bash\nmix phx.server\n```\n\nYou can now visit [`localhost:4000`](http://localhost:4000) from your browser or test the API using a tool like Postman.\n\n### 5. Running Tests\nRun the following command to execute the tests:\n```bash\nmix test\n```\n\n\n## Order Processing\nOrder processing happens asynchronously, and status updates are logged in the `OrderLogs`.\n\n### Asynchronous Order Handling\n- Each order is processed asynchronously via Oban jobs. \n- Orders are processed in two phases:\n  1. **Reserve Inventory**: Ensure sufficient inventory exists before processing the order.\n  2. **Payment Processing**: A payment simulation is made asynchronously. If it fails, the system retries the order until a limit is reached.\n\n### Retry Mechanism\n- Orders that fail due to insufficient inventory or payment failure are retried up to 3 times.\n- If retries are exhausted, inventory is released.\n\n## Database Schema\n\n### Tables\n\n- **Products**: Stores product details (`id`, `name`, `description`, `price`).\n- **Inventory**: Tracks product inventory levels (`id`, `product_id`, `quantity`).\n- **Orders**: Manages customer orders (`id`, `product_id`, `quantity`, `status`).\n- **OrderLogs**: Logs the processing status of each order (`id`, `order_id`, `status`, `processed_at`, `error_message`).\n\n### Database Migrations\nMigrations are used to alter the database schema without causing downtime. For example, the migration to introduce product categories includes:\n- Creating the `Categories` table (`id`, `name`).\n- Creating the `Product_Categories` table (`product_id`, `category_id`).\n\n```bash\nmix ecto.gen.migration create_categories\nmix ecto.migrate\n```\n\n## Resiliency and Distributed Consistency\n\nThe service simulates an external payment system. If the payment succeeds, the order is marked as processed. If the payment fails, inventory is released, and the system retries the payment after a delay.\n\n### Failure Handling\n- Simulates payment delays and random failures.\n- Ensures eventual consistency in inventory and order status.\n\n## License\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolobarine%2Florcan_bet_async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolobarine%2Florcan_bet_async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolobarine%2Florcan_bet_async/lists"}