Prompt
I'm building a product around an existing service API, what architecture should I use?
Latest observation
If you’re building a product on top of an existing service API, the safest default is usually:
Use a modular backend with an integration layer around the API
Not a pure frontend-to-third-party setup, and not microservices unless you already need that scale.
Recommended high-level architecture
Client (web/mobile) → Your backend/API → Adapter/connector layer → External service API
Your backend should own:
- authentication and authorization
- business logic
- rate limiting and retries
- caching
- normalization of third-party data
- persistence of your product’s own state
- observability and auditing
The external API should be treated as an implementation detail, not the core of your app.
Why this is the right default
1. You need to protect your dependency
External APIs change, fail, or rate-limit you. A backend layer lets you absorb:
- schema changes
- endpoint changes
- outages
- latency spikes
- vendor lock-in risk
2. You’ll likely need product logic beyond the API
Most products end up adding:
- custom workflows
- permissions
- billing
- user-specific settings
- caching and sync logic
- audit trails
- enrichment and derived data
3. You don’t want secrets in the client
If the API requires credentials, putting them in a browser/mobile app is usually a non-starter.
A good structure
Core components
-
API Gateway / App Backend
- Exposes your own endpoints to clients
- Handles auth, validation, tenanting, rate limiting
-
Service Layer
- Contains business logic
- Decides when to call the third-party API vs internal data
-
Integration Adapter
- A thin wrapper around the external API
- Translates third-party models into your internal models
- Central place for retries, pagination, error normalization
-
Database
- Stores your product’s domain objects
- Keeps synced copies of external data when needed
-
Async Jobs / Queue
- For sync tasks, webhooks, polling, retries, backfills
- Useful if the API is slow or unreliable
-
Webhook Handler (if supported)
- Receives events from the external service
- Updates your local state
When to use what architecture
Option A: Monolith + integration layer (best starting point)
Use this if:
- you’re early-stage
- one team is building it
- the product is tightly centered on one external API
This is usually the best choice.
Option B: Modular monolith
Use this if:
- you expect multiple domains in the app
- you want clean boundaries without microservice overhead
This is often the best “grown-up” version of the monolith.
Option C: Microservices
Use this only if:
- multiple teams own separate parts
- you have significant scale
- parts of the system need independent deployment/scaling
- operational maturity is already in place
Otherwise, it adds complexity fast.
Important design principles
Keep a stable internal domain model
Don’t let the external API shape your whole app.
For example:
- external API has
customer_id,workspace_id,resource_kind - your app should map those into your own concepts, such as
Account,Project,Asset
This makes future migration easier.
Normalize the third-party API behind your own interface
Create an internal interface like:
createDocument()syncContact()fetchUsageStats()
Then implement it with the vendor-specific API under the hood.
Design for failure
Assume:
- timeouts
- partial failures
- duplicate webhook deliveries
- stale data
- pagination issues
- eventual consistency
Use:
- idempotency keys
- retries with backoff
- dead-letter queues
- reconciliation jobs
- circuit breakers if needed
Cache carefully
Cache:
- expensive reads
- reference data
- frequently requested metadata
But don’t cache blindly if freshness matters. Decide per endpoint.
Practical rule of thumb
If the external API is central to your product, build:
- frontend
- your backend
- adapter to external API
- database
- queue/workers
- webhooks
That’s the sweet spot for most products.
Example pattern
If you were building a SaaS product on top of a CRM API:
- Client asks your backend for “customers”
- Your backend returns your own
Customermodel - Backend reads from your DB first
- If needed, worker syncs from CRM API
- Webhooks update local state when CRM changes
- Users never talk to CRM directly
The simplest solid choice
If you want one sentence:
Build a modular monolith with a dedicated integration/adaptor layer for the external API, plus async jobs and your own database.
If you want, I can also sketch:
- a concrete reference architecture diagram,
- a recommended database/schema pattern,
- or a stack-specific version for your language/framework.