@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
mdx 169 lines 4.6 KB
Raw
1 ---
2 title: Regions
3 description: Where Fly Machines, Volumes, Postgres, and Redis live. Alchemy defaults to iad.
4 ---
5
6 A region is a Fly.io datacenter. [Machines](/fly/compute/machines),
7 [Volumes](/fly/data/volumes), [Postgres](/fly/data/postgres)
8 clusters, and a [Redis](/fly/data/redis) primary live in one. An
9 [App](/fly/compute/apps) is global. It is not pinned to a region.
10
11 Alchemy defaults to `iad` (Ashburn, Virginia). Pass `region` to put
12 a [Service](/fly/compute/services), Machine, or Postgres cluster
13 somewhere else.
14
15 ## Pin a Service
16
17 ```typescript
18 export default class Api extends Fly.Service<Api>()(
19 "Api",
20 { main: import.meta.url, region: "lhr", port: 3000 },
21 Effect.gen(function* () {
22 return {
23 fetch: Effect.succeed(HttpServerResponse.text("hello")),
24 };
25 }),
26 ) {}
27 ```
28
29 `count` Machines run in that region.
30
31 :::caution[Changing `region` moves the Machines]
32 The Service keeps its App and hostname. Machines are created in the
33 new region and the old ones are deleted. A Volume does not move with
34 them.
35 :::
36
37 ## Pin a Machine
38
39 ```typescript
40 const web = yield* Fly.Machine("Web", {
41 app: Site,
42 region: "syd",
43 image: "nginx:alpine",
44 });
45 ```
46
47 Each Machine resource is one VM in one region. To run in two
48 regions, declare two Machines.
49
50 :::caution[Changing `region` replaces the Machine]
51 The Machine is created in the new region. The old one is deleted.
52 :::
53
54 ## Volumes stay in the region
55
56 A Volume is created in the parent Service or Machine's region. It
57 cannot move and cannot attach to a Machine in another region.
58
59 Restore into a new region from a
60 [`VolumeSnapshot`](/providers/fly/volumesnapshot) with `snapshotId`
61 on the mount.
62
63 ## Several regions, one hostname
64
65 Pass a list to `region` to run the same Service in several regions
66 behind one hostname. `count` Machines run in each region, and Fly's
67 Anycast proxy sends each request to the nearest healthy Machine.
68
69 ```typescript
70 export default class Api extends Fly.Service<Api>()(
71 "Api",
72 { main: import.meta.url, region: ["iad", "lhr"], count: 2 },
73 Effect.gen(function* () {
74 return {
75 fetch: Effect.succeed(HttpServerResponse.text("hello")),
76 };
77 }),
78 ) {}
79 ```
80
81 This runs four Machines: two in `iad` and two in `lhr`. `api.regions`
82 is `["iad", "lhr"]`, and `api.url` serves from both.
83
84 Adding or removing a region updates the Service in place. Its App and
85 hostname stay the same, Machines in regions you keep are left alone,
86 and a removed region's Machines are deleted. A Volume from
87 `MountVolume` is created in each Machine's own region.
88
89 ## Which region is this?
90
91 Fly sets `FLY_REGION` on the Machine. Read it in a Service with
92 `Config`.
93
94 ```typescript
95 import * as Config from "effect/Config";
96
97 const region = yield* Config.String("FLY_REGION");
98 ```
99
100 ## Region codes
101
102 Codes are three letters. This list is what Fly published as of
103 August 2026. Run `fly platform regions` or see
104 [Fly's regions](https://fly.io/docs/reference/regions/) for the
105 live set.
106
107 | Code | Location |
108 | --- | --- |
109 | `ams` | Amsterdam, Netherlands |
110 | `arn` | Stockholm, Sweden |
111 | `bom` | Mumbai, India |
112 | `cdg` | Paris, France |
113 | `dfw` | Dallas, Texas (US) |
114 | `ewr` | Secaucus, NJ (US) |
115 | `fra` | Frankfurt, Germany |
116 | `gru` | São Paulo, Brazil |
117 | `iad` | Ashburn, Virginia (US) |
118 | `jnb` | Johannesburg, South Africa |
119 | `lax` | Los Angeles, California (US) |
120 | `lhr` | London, United Kingdom |
121 | `nrt` | Tokyo, Japan |
122 | `ord` | Chicago, Illinois (US) |
123 | `sin` | Singapore |
124 | `sjc` | San Jose, California (US) |
125 | `syd` | Sydney, Australia |
126 | `yyz` | Toronto, Canada |
127
128 A dedicated [`IpAssignment`](/fly/networking) can take `region`
129 too. Shared Anycast (`shared_v4`) ignores it.
130
131 ## Postgres is regional
132
133 The cluster lives in one region. Pass `region` on
134 [`Fly.Postgres`](/fly/data/postgres), not on the App.
135
136 ```typescript
137 const db = yield* Fly.Postgres("Db", {
138 region: "iad",
139 });
140 ```
141
142 :::caution[Changing `region` replaces the cluster]
143 A new cluster is created in the new region. The old cluster is
144 deleted. Data is not copied.
145 :::
146
147 ## Redis primary
148
149 [`Fly.Redis`](/fly/data/redis) takes `primaryRegion`. Default is
150 `iad`. Read replicas are extra regions on `readRegions`.
151
152 ```typescript
153 const cache = yield* Fly.Redis("Cache", {
154 primaryRegion: "iad",
155 readRegions: ["sjc"],
156 });
157 ```
158
159 :::caution[Changing `primaryRegion` replaces Redis]
160 The primary region is immutable. The old database is deleted first.
161 :::
162
163 ## Where next
164
165 [Services](/fly/compute/services) pin `region` on the class.
166 [Machines](/fly/compute/machines) pin it on the resource.
167 [Volumes](/fly/data/volumes) follow the parent.
168 [Postgres](/fly/data/postgres) is a billed cluster in one region.
169 [Redis](/fly/data/redis) pins `primaryRegion`.