Learn Hub / General

Why Developers Need Fallback Logic in Embedded APIs

Build resilient embedded APIs with fallback logic, safe retries, queues, and compliant e-invoicing workflows across markets.

DDD Invoices logoWritten by Compliance & Growth Team
Denis, DDD Invoices reviewerReviewed by Denis
August 20, 2026
General

When embedded APIs support invoicing, ERP, fintech, or accounting workflows, an external-service failure can interrupt the entire user journey. An invoice may be created successfully, but submission can fail because the API times out, the provider rate-limits the request, or the external platform returns no clear status. The real risk is uncertainty, the application may not know whether the invoice is pending, failed, or already processed.

Depending on the failure, the system can retry safely, queue the request, pause calls to an unavailable service, or keep the invoice in a pending state until confirmation arrives. In e-invoicing and other compliance workflows, the system should never mark a transaction as complete until submission or validation has been confirmed.

 

What actually breaks when an embedded API fails

An embedded API can fail at several points in the workflow, and each type of failure leaves the application in a different state. For developers, the challenge is not only detecting that something went wrong, but deciding whether the request should be retried, queued, rejected, or checked before any further action is taken.

  • 5xx errors or outages: The provider cannot complete the request. Preserve the transaction, stop repeated calls when necessary, and retry only after the service recovers.
  • 429 rate limits: The API is available but rejects excess traffic. Respect the provider’s retry instructions, apply backoff, and queue requests where appropriate.
  • Timeouts: The response never arrives, leaving the transaction status unclear. For invoice submissions, an immediate retry can risk creating duplicates, so the system should first check whether the original request was processed.
  • Invalid responses: A 200 response does not guarantee the data is complete or usable. Structured e-invoices still need to meet required fields, allowed values, and validation rules. 
  • Schema changes: Changes to fields, data types, code lists, or required values can break downstream processing even when the API itself is online.

An invoice can exist in the ERP while its external submission status is still unclear. The safest approach is to keep it pending, verify the downstream status, and retry only when it is safe, making strong embedded APIs error handling essential for e-invoicing.

 

Fallback design patterns every developer should know

The importance of API fallback is not to hide every failure. It is to choose a controlled response that matches the risk of the operation, protects the transaction, and gives the application a clear next step. The best fallback strategies for APIs depend on whether the request is a read, a write, or a compliance-sensitive submission.

  • Retries with exponential backoff and jitter: Retry temporary failures with increasing wait times and a small random delay. Only retry idempotent operations. 
  • Circuit breakers: Stop requests after repeated failures and resume them after a cooldown period, preventing repeated calls to an unavailable service.
  • Cache-aside or stale-while-revalidate: Use cached data when live data is unavailable, with a defined freshness limit.
  • Queue-and-retry: Store failed requests and retry them when the provider recovers, using idempotency keys to prevent duplicates. 
  • Deterministic mode: Uses pre-validated rules when external lookups are unavailable, ensuring reliable results.
  • Human review: Route high-risk or unclear cases to a manual review queue when automation cannot confirm whether the transaction is correct, complete, or already processed.

Multi-provider failover can work well for non-regulated enrichment services, such as address or company-data lookups. However, it is not automatically safe for e-invoicing or tax workflows. A secondary provider must support the relevant jurisdiction, required fields, validation rules, and processing status.

 

Where should you put fallback logic?

Fallback logic should not live in a single layer of the application. Each layer has a different level of context, the gateway manages traffic, the service understands the transaction, and the client communicates the outcome to the user. Separating these responsibilities makes embedded API error handling easier to maintain and prevents technical failures from turning into incorrect business or compliance decisions. 

Factor

Gateway

Service

Client

Policy enforcement

High

Medium

Low

Business context

Low

High

Medium

Credential security

High

High

Low

Duplication risk

Low

High

Low

Schema validation

Low

High

Low

User feedback speed

Medium

Medium

High

The gateway should manage technical controls around API traffic. It can enforce timeouts, apply limited retries, and stop repeated calls to an unhealthy dependency.

The service layer should handle the more important fallback decisions because it understands the transaction itself. In an invoicing workflow, this is where the system can decide whether an invoice is still pending, whether the response is valid, and whether a retry is safe.

The client layer should focus on communicating that state clearly to the user, for example by showing that an invoice is still being processed rather than simply displaying a generic error.

Compliance decisions should stay out of the client layer. The interface should not decide whether an invoice is compliant, accepted, or safe to resubmit, because it usually does not have the full transaction history or validation context. Those decisions belong in the service layer, where the application can apply consistent rules and maintain a reliable audit trail.

 

How to keep fallback outputs compliant and schema-compatible

A fallback response that has the wrong fields, totals, or status can create more risk than an obvious error. The goal is semantic parity and interoperability, the fallback must preserve the information and rules needed for the intended invoice workflow.

Every fallback path should validate:

  • Required supplier, buyer, tax, currency, and line-item information.
  • Field types, code lists, and identifiers against the canonical schema.
  • Whether line totals, tax totals, and payable amounts reconcile correctly.
  • The original request, fallback action, timestamps, status changes, and replay outcome.
  • Whether an invoice is awaiting submission, rejected, or acknowledged by the relevant receiving platform.

The European Commission publishes supporting artefacts for EN 16931 implementation, including validation rules and maintained code lists. These resources illustrate why developers should validate against a controlled version of the relevant specification rather than assume a successful HTTP response equals a valid invoice.

Retention, signature, timestamping, and archiving obligations vary by country and use case. Do not assume one global fallback policy meets every requirement. For example, the IRS requires machine-readable records to remain available for as long as they may be material to tax administration.

 

How DDD Invoices helps you scale compliant e-invoicing

DDD Invoices provides a unified API that lets software platforms send standardized invoice data in JSON and manage e-invoicing across multiple countries through one integration. The platform converts that data into locally compliant outputs, including legally valid PDF invoices and structured XML e-invoices, while applying the relevant tax rules, VAT rates and exemptions, language, currency, and formatting requirements.

DDD Invoices can issue and receive e-invoices, generate country-specific invoice formats, support fiscalization requirements such as QR codes, and submit real-time or periodic reports to tax authorities where required. It can also use AI to extract data, validate that data, and deliver it into ERP, accounting, and other finance systems, helping teams reduce manual entry and maintain compliant invoicing workflows.

Still have questions?

Talk to us!

In the 30min free call we will discuss:

  • your requirements in invoicing
  • how integration works
  • demo of the product
  • next steps
Book a free 30min call

 

FAQs

Why use a unified API for e-invoicing?

A unified API lets you connect once instead of building separate integrations for each country. DDD Invoices handles the local tax, format, and reporting requirements behind the scenes.

How does DDD Invoices turn JSON into compliant invoices?

Your system sends standardized JSON invoice data. DDD Invoices converts it into the locally required PDF or XML format, applying the correct language, currency, VAT rules, exemptions, and fiscalization requirements.

Can DDD Invoices help us expand into new markets?

Yes. The platform is built for multi-country operations, so software providers can support local e-invoicing requirements without developing a new country-specific integration each time.

What happens when local e-invoicing rules change?

DDD Invoices manages the compliance layer and is designed to adapt to evolving country requirements, including Continuous Transaction Control models and tax-authority reporting obligations.