This month's AWS bill for notes-api's attachments is $183.50. The surprise: $171 of it isn't storage. It's for the 2,000 GB of attachments users downloaded this month, at an example price: the first 100 GB free, then $0.09 per GB. Moving some of it to another provider sounds sensible. The question is how far to go.
Multi-cloud means using more than one cloud provider. It usually means picking the best provider for each need, not running everything on every provider at once. Picture organising a wedding reception. The tent comes from a tent rental company, the sound system from another rental company, and the photos from a studio you know. Each need comes from the vendor (the company that provides it) that suits it best, and that is normal. It is a different matter when you hold two complete receptions in two places at the same time. The idea is that if the power fails in one place, the party can go on in the other. It works, but everything doubles: the tents, the sound systems, the crews and the cost. The programme also has to work with different equipment in each place. In notes-api, each vendor is one provider, for example Cloudflare or AWS. The second reception is the same API and database running on a second cloud, and the power cut is one provider failing completely. This lesson shows the difference between the two ways for notes-api, and why the answer is usually: don't hold the second reception.
notes-api is already multi-vendor
Look again at what this track has built:
| Part | Provider | Why there |
|---|---|---|
The notes-api API on web-1, web-2 |
a rented VPS | cheap, full control |
DNS, CDN, the Worker notes-edge |
Cloudflare | an edge close to visitors |
The frontend notes-web (Next.js) |
Vercel | Next.js deploys without fuss |
The notes-attachments bucket, the Lambda notes-export |
AWS, eu-west-2 London |
object storage and FaaS |
| Repo and CI/CD | GitHub | Actions next to the code |
That is already "multi-cloud" in the first sense: every need gets the provider that suits it (best-of-breed, the best in its field). Every part runs in one place only. The expensive one is the second sense: active-active, the same API and database running on two clouds at once.
Lock-in vs complexity
Vendor lock-in is when moving away from a provider gets expensive, because your code and data are tied to that provider's own services. Examples: a Lambda handler that reads API Gateway events, or a Worker that uses KV and Durable Objects. No other provider has a service identical to them.
Avoiding lock-in by running the app on two clouds brings another problem: complexity. Every extra provider brings a whole set of its own things to manage. This table uses the Lab's numbers and shows what doubles if notes-api goes active-active on AWS and Google Cloud:
| What has to be managed | One cloud | Active-active on two clouds |
|---|---|---|
| Permission systems (IAM) and billing accounts | 1 | 2 |
| Monitoring and alert dashboards | 1 | 2 |
| Providers in Terraform | 1 | 2 |
| Databases | 1 Postgres | 2 Postgres + cross-cloud replication |
| Extra cost per month (example) | $0 | $126 (compute $48 + Postgres $60 + replication $18) |
Compute in the last row means the servers that run the API. Replication is copying the data all the time from the first Postgres to the second one, over the network between the clouds.
For a team of two, doubling everything in that table is usually more dangerous than the lock-in it tries to avoid. More configuration means more places to get it wrong.
Egress: the cost people forget
Egress is data that leaves a cloud, and it is paid per GB (the Cloud Computing Basics lesson). This includes data flowing to another cloud. Incoming data is usually free. So the sending provider is the one who bills. Here is an example monthly bill for notes-api's attachments. It covers 500 GB stored, 2,000 GB downloaded by users, and 300 GB read by the Lambda notes-export on AWS to embed in PDFs:
| Bucket on | Store 500 GB | Downloaded 2,000 GB | Read by Lambda 300 GB | Total |
|---|---|---|---|---|
| S3 London | $12.50 | $171 (100 GB free) | $0 (same region) | $183.50 |
| Cloudflare R2 | $7.50 | $0 | $0 | $7.50 |
| Google Cloud Storage London | $11.50 | $240 | $36 (cross-cloud) | $287.50 |
R2 charges no egress at all, so the downloads cost $0. The prices in this table are examples for calculating, not current prices, so check each provider's pricing page first. Per-operation costs (per upload, per download) are left out too, since they are small here.
The column "Read by Lambda 300 GB" shows the cross-cloud risk. Say an API on AWS pulls big images from Google Cloud Storage on every request. You pay a transfer cost on every request, and you wait for the latency of the network between clouds, which is slower than the network inside one region.
The portable pieces
You can reduce lock-in without running two clouds, by choosing pieces that are portable (easy to move to another provider):
- Containers: the same Docker image runs on a VPS, on AWS or on Google Cloud.
- Terraform: the tool is the same for every provider, but its resources are not.
aws_s3_buckethas to be rewritten asgoogle_storage_bucketto move to Google. Terraform makes a move easier, but it doesn't make it automatic. - S3-compatible APIs: R2, Google Cloud Storage, DigitalOcean Spaces and MinIO accept S3 API calls. So the same SDK only needs another
endpoint(the address of the storage server the SDK talks to). - Standard Postgres: plain SQL runs on any Postgres. Only the special features of one provider's managed database tie you to that provider.
An abstraction layer (code that sits between the app and the provider) turns a provider move into a one-file job. In this example, StorageProvider is an interface: a list of the methods every storage class must have. implements StorageProvider means the class S3CompatibleStorage must have all the methods of that interface:
// storage.ts: the rest of the code only knows this interface
import { S3Client, PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl as presign } from "@aws-sdk/s3-request-presigner";
export interface StorageProvider {
upload(key: string, data: Uint8Array): Promise<void>;
download(key: string): Promise<Uint8Array>;
delete(key: string): Promise<void>;
getSignedUrl(key: string, expiresIn: number): Promise<string>;
}
// One class for every provider that speaks the S3 API
export class S3CompatibleStorage implements StorageProvider {
constructor(private s3: S3Client, private bucket: string) {}
async upload(key: string, data: Uint8Array) {
await this.s3.send(new PutObjectCommand({ Bucket: this.bucket, Key: key, Body: data }));
}
async download(key: string) {
const res = await this.s3.send(new GetObjectCommand({ Bucket: this.bucket, Key: key }));
return res.Body!.transformToByteArray();
}
async delete(key: string) {
await this.s3.send(new DeleteObjectCommand({ Bucket: this.bucket, Key: key }));
}
getSignedUrl(key: string, expiresIn: number) {
return presign(this.s3, new GetObjectCommand({ Bucket: this.bucket, Key: key }), { expiresIn });
}
}
// What differs between providers is only the S3Client config:
const s3 = new S3Client({ region: "eu-west-2" }); // S3 London
// R2: new S3Client({ region: "auto", endpoint: `https://${accountId}.r2.cloudflarestorage.com`, credentials })
export const attachments: StorageProvider = new S3CompatibleStorage(s3, "notes-attachments");
- Routes and jobs (tasks that run in the background) only call
attachments.upload(...)andattachments.getSignedUrl(...), neverS3Clientdirectly. - Moving from S3 to R2 only means changing the
S3Clientconfig, or adding a new implementation class such asR2Storage(another class that fits the same interface). The calling code stays the same. - Compatible doesn't mean identical: lifecycle rules, storage classes and new SDK features can differ by provider. Test before you move.
When two clouds are really needed
Start from the need, not from the strategy. This table holds the rules the decision helper in the Lab uses:
| Need | The answer that is usually enough |
|---|---|
| Attachments are downloaded by the terabyte each month | move the attachments to storage with no egress (R2) or behind a CDN: one extra vendor for one need |
| A client requires the data to stay in the UK (data residency) | pick a London region at one provider (AWS eu-west-2, Google europe-west2). This is about the region, not the number of clouds. R2 doesn't guarantee the data stays in the UK |
| It must keep running even if one provider stops completely | the only strong reason for active-active on two clouds, and only if the team is big enough to maintain it. Start with two regions at one provider |
| Afraid of lock-in | use the portable pieces (containers, Terraform, the S3 API, Postgres) and an abstraction layer |
| A team of only two | one main provider, as few extra vendors as possible |
⚠️ Wrong assumptions that make multi-cloud expensive
- Active-active "to be safe" without a real need. Cost and the number of things to manage double. Yet a complete outage (the service fully stopped) at one provider is far rarer than a misconfiguration.
- Forgetting cross-cloud egress. Compute on one cloud that reads big data from another pays for the transfer on every request.
- Thinking Terraform makes infrastructure portable. Its resources still belong to one provider.
- Treating S3-compatible as exactly S3. Test the features you use at the new provider before moving the data.
TL;DR: Multi-cloud means using more than one cloud provider. The healthy version is best-of-breed: each need gets its best provider, like notes-api with a VPS, Cloudflare, Vercel and AWS. The active-active version (the same API and database on two clouds at once) doubles IAM (the permission system), billing, monitoring, Terraform and the database. In the Lab that costs +$126 a month, and it is usually not worth it for a small team. Egress (data leaving a cloud) is billed by the sending provider. At example prices, 2,000 GB of attachments downloaded by users in a month cost $171 on S3 and $0 on R2. Data pulled across clouds brings transfer costs and latency (network waiting time). Reduce lock-in (being tied to one provider's own services) with pieces that are easy to move (portable): containers, Terraform, S3-compatible APIs and Postgres. Add an abstraction layer too (code between the app and the provider), such as the interface StorageProvider: the list of storage methods the rest of the code calls. Then moving from S3 to R2 only means changing its implementation (the class that fills in those methods), and the calling code stays the same. Data residency (a rule that data must stay in a certain country) is solved with a region, not with a second cloud.
⚡ Best-of-breed, not active-active
Meaning: Healthy multi-cloud (using more than one cloud provider) is best-of-breed: each need gets the provider that fits it best, and each part runs in only one place. Active-active, the same API and database running on two clouds at once, doubles IAM (the permission system), billing, monitoring, Terraform and the database: +$126 a month in the Lab.
⚡ The sender pays for egress
Guess first: egress is data leaving a cloud, and it is paid per GB. An API on AWS pulls 300 GB from Google Cloud Storage. Who bills for it?
Google, because Google is the sender. Data leaving a cloud is paid per GB, while incoming data is usually free. Cloudflare's R2 charges no egress at all.
Meaning: Compute (the servers that run the app) in one cloud that reads big data from another cloud pays a transfer cost on every request.
⚡ An abstraction layer
Write:
// What differs between providers is only the S3Client config:
const s3 = new S3Client({ region: "eu-west-2" }); // S3 London
export const attachments: StorageProvider = new S3CompatibleStorage(s3, "notes-attachments");
Meaning: An abstraction layer is code between the app and the provider. Here it is the interface StorageProvider: a list of storage methods (upload, download, delete, getSignedUrl) that every storage class must have. attachments is made from the class S3CompatibleStorage with the bucket notes-attachments. Routes and jobs (tasks that run in the background) only call attachments.upload(...). Moving from S3 to R2 only means changing the S3Client config (its region and storage address), or adding a new implementation class (another storage class with the same methods). The calling code stays the same.