Skip to content

[FEATURE REQUEST]: Add /batch Endpoint for Batch Request Processing #688

Description

@fredcamaral

Overview

I'm requesting the addition of a /batch endpoint to the Midaz API to enable efficient processing of multiple API requests in a single HTTP call. The Go SDK already includes a comprehensive HTTP batch processor implementation (pkg/concurrent/http_batch.go), but it currently can't be fully utilized without a corresponding server-side endpoint.

Current Situation

  • The SDK includes an implemented HTTPBatchProcessor in pkg/concurrent/http_batch.go
  • This processor is designed to send multiple requests to a /batch endpoint
  • Currently, there is no /batch endpoint on the Midaz API
  • Without this endpoint, batch operations fall back to individual requests, adding overhead and reducing performance

Benefits of a Batch Endpoint

  1. Reduced Network Overhead: Multiple operations in a single HTTP request
  2. Improved Performance: Fewer connection establishments and reduced latency
  3. Atomic Operations: Ability to process related requests together
  4. Better Resource Utilization: Server can optimize processing of multiple requests
  5. Leveraging Existing Code: The SDK already has the client-side implementation

Proposed Implementation

The batch endpoint should:

  • Accept a POST request to /batch
  • Receive an array of request objects, each containing:
    • method: HTTP method (GET, POST, PUT, DELETE, etc.)
    • path: Relative path for the request
    • headers: Optional request-specific headers
    • body: Optional request body
    • id: Client-generated ID to match requests with responses
  • Return an array of response objects, each containing:
    • statusCode: HTTP status code
    • headers: Response headers
    • body: Response body
    • error: Error message (if applicable)
    • id: The client-generated ID from the request

Example Request

[
  {
    "method": "GET",
    "path": "/.../transactions/batch",
    "id": "req_1"
  },
  {
    "method": "POST",
    "path": "/.../transactions/batch",
    "body": {
      various transactions bodies
    },
  }
]

Example Response

[
  {
    "id": "req_1",
    "statusCode": 200,
    "body": {
      ...
    }
  },
  {
    "id": "req_2",
    "statusCode": 201,
    "body": {
      ...
    }
  }
]

Priority and Impact

This feature would significantly improve performance for operations that require multiple API calls, such as:

  • Creating complex workflows with multiple entities
  • Batch processing transactions
  • Retrieving data for dashboards and reports

Additional Considerations

  • Rate limiting should be adjusted to account for batch requests
  • Authentication should be handled at the batch level
  • Error handling should allow for partial success/failure

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions