Skip to main content

How to Handle Salesforce API Limits with FastAPI

About Us
Published by yuliya.dzemidchuk
27 March 2026

How to Work Around Salesforce API Limits with FastAPI

 

The Reality of Salesforce API Integrations

You’ve just been asked to connect a new customer portal, ERP system, or internal dashboard to Salesforce. It sounds straightforward on paper — Salesforce has excellent REST APIs, right?

However, in practice, challenges begin to emerge quickly.

You quickly discover that Salesforce’s native APIs are powerful… but raw, restrictive, and unforgiving in real-world enterprise scenarios.

The biggest culprit? Governor limits and the platform’s multi-tenant architecture. All enterprises have daily API request quotas that vary by edition and configuration (often in the range of tens to hundreds of thousands of calls per 24 hours, plus license-based extras). On top of that, concurrent request limits — Salesforce enforces limits such as allowing only 25 long-running calls (>20 seconds) allowed at once on PROD.

Then there’s the REST API itself. It’s synchronous and great for small, real-time operations, but it has hard caps: maximum 2,000 records per query, 6 MB payload size. Want to process 10,000 leads or sync inventory in one go? You have two options: either make hundreds of individual calls (burning through your daily quota in hours) or utilize “Bulk API 2.0”.

On top of the technical limits, you face constant data-quality battles. Salesforce returns verbose, sometimes inconsistent payloads. Field mappings break when objects change. Business rules (lead scoring, duplicate prevention, approval workflows) must be enforced somewhere — but doing it directly in every calling system leads to duplicated logic, inconsistent results, and corrupted records. Authentication tokens expire, error handling varies between endpoints, and exposing raw Salesforce credentials to frontends or external partners is a security nightmare.

The result in real projects?

  • Integrations that work in dev but collapse under moderate load.
  • Teams are spending more time fighting limits and debugging than delivering features.
  • Data inconsistencies that erode trust in the CRM.
  • Slow onboarding of new systems because every connection re-invents the wheel.
  • Production incidents when a marketing campaign or nightly sync suddenly spikes API usage.

This scenario is common across many enterprise implementations. What should be a simple data flow turns into a constant battle against the platform’s built-in safeguards — safeguards that exist for good reasons (fair resource sharing in a multi-tenant world) but make life difficult when you need reliable, scalable, and secure access to Salesforce.

This level of complexity is often unnecessary and can be avoided with the right architectural approach.

 

The Solution: Build a Smart API Layer with FastAPI

This is where FastAPI becomes a practical and effective solution. By placing a FastAPI layer between your applications and Salesforce, you regain control, improve reliability, and protect your integrations.

FastAPI is well-suited for Salesforce because it’s extremely fast, built on modern Python standards (Pydantic for validation, Starlette for performance), and excels at creating clean, documented APIs with minimal boilerplate. It lets you handle data processing, validation, and orchestration in Python before anything ever touches Salesforce.

Here’s how this architecture works in practice:

 

Middleware as the Polite Middleman

Think of middleware as the polite bouncer (or middleman) at your backend’s door. It runs on every request and can:

  • Add timing headers (X-Process-Time)
  • Handle logging
  • Enforce authentication and token refresh for Salesforce
  • Normalize responses

Your consumers receive clean, consistent, predictable data every single time — no more zoo of errors in the logs.

 

CORS and Request Handling

When different parts of your system (or frontend) talk to the API from different ports or domains, browsers and clients can block requests. Proper CORS configuration ensures everything communicates smoothly, and you can easily maintain and tune it as the project grows.

 

Smart Data Validation and Processing

Using FastAPI’s tight integration with Pydantic, you validate and transform data in Python before sending it to Salesforce. This catches invalid fields, enforces business rules, and prevents bad data from polluting your CRM.

 

How FastAPI Helps with Governor Limits

FastAPI provides practical tools to stay within Salesforce limits. These include caching for repeated queries, batching and aggregation to reduce the number of API calls, and background queues for heavy or non-urgent operations. This flexibility allows multiple strategies for optimizing API usage. Instead of letting every system fire hundreds of direct calls, you consolidate and optimize all traffic through one controlled, intelligent layer — significantly reducing the total number of calls to Salesforce.

 

Docker for Consistent Development

During normal development you’re often forced to juggle multiple CLIs. With a proper setup, you run just one command, and everything starts together in a reproducible environment:

Bash

docker compose up --build

No more “it works on my machine” drama.

 

Preparing for Production with API Gateway

When you’re ready to go live with a real hosting provider, keep in mind real security, scalability, and rate limiting. We will put an API Gateway (for example AWS API Gateway) in front of your FastAPI service. This is an extra layer of protection while your FastAPI backend stays focused on business logic.

 

Real Impact

This approach helps teams move faster, reduce bugs, improve data quality, and make Salesforce integrations much more secure and maintainable.

In practice, these patterns are typically implemented through a structured API layer — with clean middleware, proper CORS configuration, Docker-based environments, and a foundation ready for an API Gateway.


Ivan Andreyeu
Python developer
image
Expertise
Question to the expert
image

We have available resources to start working on your project within 5 business days

1 UX Designer

image

1 Admin

image

2 QA engineers

image

1 Consultant

image
Related Articles
All articles
image
Is Salesforce Winning the Public Sector Race?
An analysis of Salesforce's rapid expansion into the U.S. public sector, tracing its path from cautious early government licensing deals in the 2010s through the launch of Government Cloud in 2012, its pivotal role in COVID-19 vaccine rollouts, and its 2025–2026 push into military and intelligence work via Agentforce and Missionforce. The piece covers major 2026 contracts — including a $5.6 billion Army deal, a $1.6 billion VA agreement, and Pentagon Impact Level 5 authorization — alongside real-world case studies like California's REAL ID processing and the UK's NHS back-office operations. It also examines the structural obstacles still facing Salesforce and other vendors in government tech: legacy IT systems decades old, outdated federal procurement rules, budget constraints, and organizational caution around AI adoption, plus the competitive pressure from Palantir, Microsoft, and Oracle in the race for public sector AI spending.
28 August 2026
image
Why Your Salesforce Flows Are Agentforce's Biggest Problem
This article argues that the most underestimated risk in Agentforce deployments isn't data quality — it's the automation layer: years of overlapping Flows, Process Builder processes, Apex triggers, and managed package logic that no one has reviewed end-to-end. It explains why AI agents inherit automation complexity without the tribal knowledge human admins carry, why technical debt only becomes visible after an agent hits it in production, and why a clean demo is no indicator of production readiness. The article closes with a concrete, tool-by-tool inventory approach using Flow Trigger Explorer, Salesforce Optimizer, Setup Audit Trail, Apex Debug Logs, Agent Builder, and Health Check — scoped to the specific processes the agent will actually use rather than the whole org.
23 July 2026
image
How to Wire Multiple Salesforce Projects in One Org Without Breaking Everything
This article maps the real integration patterns that emerge when multiple Salesforce projects — both managed packages and unpackaged code — share a single org. It covers four concrete patterns: attaching custom triggers to package-owned objects, calling global members exposed by managed packages, writing directly into another project's objects, and runtime-guarded reads of package data. It then addresses access control for authenticated and guest users, including the Master-Detail wall and the without sharing elevation pattern. The piece closes with eight concrete risks (compile-time dependencies that block uninstall, upgrade coupling, silent cascade failures, access invisible to admins) and six actionable recommendations for keeping cross-project coupling manageable.
08 July 2026