How juspay/decision-engine works
Main Components
• Decision Engine Core – This is the entry point for payment routing. It handles eligibility checks, rule-based ordering, dynamic gateway ordering, and downtime detection.
• Payment Routing Modules – These are implemented in separate crates (for example, the “dynamo” and “open-router” crates). They encapsulate specific business logic such as:
– Eligibility checks
– Contract/routing rules evaluation (seen in “contract_routing” modules)
– Health checks (modules in “health_check”)
– Success rate handling and elimination logic for dynamic gateway ordering
• Authentication & Security – Components responsible for authentication, hashing, secrets management, and encryption (spread across “src/authentication”, “src/secrets”, and several crypto-related directories in the “open-router” crate).
• Auxiliary Services – Additional supporting components such as logging, ephemeral storage (for temporary data like success rate calculations), and metrics gathering.
• Simulator & Tester – A separate crate (“simulator”) provides a way to mimic transaction flows, file storage (including S3 and local file system options), and health/simulation endpoints to test the engine.
• Configuration and Orchestration – The configuration files (under “config” and the various “config.example.toml”, “development.toml”, etc.) manage environment-specific settings and deployment parameters. The project also provides Docker and GitHub workflows, so consider a containerized deployment aspect.
Relationships and Interactions
• Validate and authenticate the request.
• Evaluate eligibility rules based on incoming payment information.
• Process routing decisions by consulting rule-based ordering modules as well as real-time success rate metrics.
• Perform health checks and dynamically reorder gateways based on downtime detection.
• Module Interactions – Emphasize how the “dynamo” crate might interact with the “open-router” as part of the decision logic. For instance, authentication modules feed data into routing decisions, and the crypto modules (in “open-router/src/crypto”) help secure secrets and data integrity.
• External Dependencies – Although not explicitly shown in code here, note that the system may interface with external PCI-compliant vaults, databases (possibly using Diesel in “open-router”), and caching layers (with Redis in “open-router/src/redis”).
Architectural Patterns & Design Principles
• Modularity via Rust Crates – The repository is split into multiple crates (dynamo, open-router, procesmo, simulator) which not only separate concerns but also allow for individual testing and provisioning.
• Layered Approach – The system separates concerns into:
– API and request handling (entry points and routing)
– Core decision logic (eligibility, rules, dynamic ordering)
– Infrastructure services (authentication, encryption, logging, health monitoring, caching)
• Use of Microservice-like Separation – Although all modules reside within one repository, they can be visualized as separate services (especially with Docker container deployments) communicating through clearly defined interfaces.