Transaction Routing

Transaction Routing is Midaz’s two-layer validation system for financial transactions, built from Transaction Routes (which define the full transaction pattern) and Operation Routes (which validate each individual operation within that pattern). Together, they ensure every transaction is both structurally correct and compliant with your business rules.

  • Transaction Routes define the complete structure of a transaction — the required sequence of operations and how they fit together to form a valid financial event.
  • Operation Routes define the rules for each individual operation (or “leg”) of that transaction, including the expected account type or specific account, the accounting annotation, and whether it’s a debit or credit.

When a transaction is submitted, Midaz validates it in two layers: Transaction Routes ensure the overall structure matches the predefined pattern, while Operation Routes confirm that each component meets account requirements and business rules.

If any part of the transaction fails these checks, it’s rejected before it can be recorded — protecting the integrity of your ledger without limiting its flexibility.

📘

Note

You define the validation patterns through Operation Routes and Transaction Routes. Midaz ensures your transactions comply with these rules before processing.


What is Transaction Routing for?


Transaction Routing provides structured control over your financial operations by separating transaction logic from business code. Instead of hardcoding validation rules in your application, you configure reusable patterns that ensure every financial movement follows your organization's requirements.

These entities are dedicated to linking Transactions and Operations from the Midaz ledger to higher-level abstractions that facilitate integration with specialized plugins and external systems, especially for accounting and treasury abstractions. The structured annotations and classifications create a standardized vocabulary that other components can understand and leverage.

This approach delivers:

  • Consistency: All transactions follow predefined structures regardless of where they originate.
  • Flexibility: Adapt your ledger design to match your business needs without code changes.
  • Integrity: Automatic validation prevents malformed transactions from affecting your ledger.
  • Maintainability: Centralized configuration makes it easier to update financial rules as your business evolves.
  • Interoperability: Business-semantic fields enable seamless integration with accounting plugins and external financial systems.

Whether you're processing simple transfers or complex multi-party transactions, Transaction Routing ensure your financial data remains structured, validated, and reliable at scale while providing the semantic foundation for advanced integrations.


Working with Transaction Routing


To use Transaction Routing, you must complete the initial configuration followed by ongoing transaction execution. Here's your step-by-step process:

Initial Setup

1. Configure Ledger for Transaction Route Validation

To activate transaction route validation for a specific ledger, you must configure it in the Transaction service. This means updating the Transaction variables in the .env file of Midaz Transaction service where you want to use route validation.

Your configuration should look like this:

# List of <organization-id>:<ledger-id> separated by comma
TRANSACTION_ROUTE_VALIDATION=

2. Create Operation Routes

Create Operation Routes that define validation rules and behavior for individual transaction components.

Key fields:

  • title: Brief label that identifies the operation route.
  • description: Optional detailed explanation.
  • metadata: Key-value pairs for business context and custom categorization.
  • operationType: source or destination indicating the operation's directional flow.
  • account: Optional validation rules specifying required account type or specific account.
    • ruleType: Type of account validation rule (account_type, alias).
    • validIf: The expected value that must match for validation to pass.

Configure them based on your needs:

Option A: No Account Rule

If you don't need account validation for the operation route, omit the account object:

 {
    "title": "Fee Collection",
    "description": "Operation route for collecting service fees from user transactions",
    "metadata": {
        "businessUnit": "payments",
        "category": "revenue"
    },
    "operationType": "source"
}

Option B: Account Validation Rule

If you need account validation for the operation, configure account rules based on your ledger setup:

  • Target Specific Account

Validate against a specific account using its alias.

{
    "title": "Fee Revenue Collection",
    "description": "Operation route for crediting collected fees to revenue account",
    "metadata": {
        "businessUnit": "payments",
        "category": "revenue"
    },
    "operationType": "destination",
    "account": {
        "ruleType": "alias",
        "validIf": "@external/BRL"
    }
}
  • Target Account Type

Validate against specific account types.

{
    "title": "User Cashout Fee",
    "description": "Operation route for collecting fees from user cashout transactions",
    "metadata": {
        "businessUnit": "payments",
        "category": "fee"
    },
    "operationType": "source",
    "account": {
        "ruleType": "account_type",
        "validIf": ["user_wallet", "asset"]
    }
}

3. Build Transaction Routes

Complete your setup by combining Operation Routes into Transaction Routes. These define your complete transaction patterns, mapping how different operations work together to form balanced financial events that match your business processes.

{
    "title": "Fee Transaction",
    "description": "Complete transaction for collecting fees from user cashout operations",
    "metadata": {
        "transactionType": "cashout_fee",
        "businessFlow": "withdrawal_processing"
    },
    "operationRoutes": [
        "0197e6aa-1695-734a-a8c3-8c79e0ad32c2",
        "0197e675-37cc-71d7-96c2-f58000f33aa0"
    ]
}

Ongoing Operations

4. Execute Validated Transactions

With your routing configuration in place, you can now submit transactions with confidence by including the ID of the previously created Transaction Route in your transaction request. Midaz will automatically validate the transaction against your defined routing patterns, ensuring consistency and integrity across all financial operations.

For the previously configured Transaction Route and Operation Routes examples, the system composes the following validation structure:

Transaction Route: "Fee Transaction" (ID: 5656daa5-5b2a-4637-955f-e43bafceaf5d)

├── Operation Route 1: "User Cashout Fee" (ID: 0197e6aa-1695-734a-a8c3-8c79e0ad32c2)
│   ├── Type: source
│   ├── Account Rule: account\_type \["user\_wallet", "asset"]
│   └── Validates: source operations in transactions
└── Operation Route 2: "Fee Revenue Collection" (ID: 0197e675-37cc-71d7-96c2-f58000f33aa0)
├── Type: destination
├── Account Rule: alias "@external/BRL"
└── Validates: destination operations in transactions

For route properties on Midaz transactions, an appropriate payload request:

{
    "route": "5656daa5-5b2a-4637-955f-e43bafceaf5d",
    "description": "Cashout fee collection transaction",
    "send": {
        "asset": "BRL",
        "value": "10",
        "source": {
            "from": [
                {
                    "accountAlias": "@user/wallet_123",
                    "amount": {
                        "asset": "BRL",
                        "value": "10"
                    },
                    "description": "Fee debit from user wallet",
                    "route": "0197e6aa-1695-734a-a8c3-8c79e0ad32c2"
                }
            ]
        },
        "distribute": {
            "to": [
                {
                    "accountAlias": "@external/BRL",
                    "amount": {
                        "asset": "BRL",
                        "value": "10"
                    },
                    "description": "Fee credit to revenue account",
                    "route": "0197e675-37cc-71d7-96c2-f58000f33aa0"
                }
            ]
        }
    }
}

When this transaction is submitted, Midaz validates that the @user/wallet_123 account matches the user_wallet account type rule, and @external/BRL matches the exact alias requirement, ensuring the transaction follows your configured routing patterns.


Managing Operation and Transaction Routes


To configure your Operation Routes, use the following endpoints:


To configure your Transaction Routes, use the following endpoints: