Edge Infrastructure
Global edge computing and offline capabilities.
Overview
The edge infrastructure provides:
| Feature | Technology | Purpose |
|---|---|---|
| Global CDN | Cloudflare | Low-latency content delivery |
| Edge Compute | Workers | Request processing at the edge |
| Offline Mode | OlympusEdge | Restaurant resilience |
| AI at Edge | Workers AI | Low-latency inference |
| Data Sync | Durable Objects | State synchronization |
Cloudflare Edge Layer
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ Cloudflare Global Network │
│ (300+ Edge Locations) │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Workers │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Router │ │ Auth │ │ Rate │ │ │
│ │ │ Worker │ │ Worker │ │ Limiter │ │ │
│ │ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │
│ └───────┼─────────────┼─────────────┼──────────────────────┘ │
│ │ │ │ │
│ ┌───────┼─────────────┼─────────────┼──────────────────────┐ │
│ │ ▼ ▼ ▼ │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ KV Store │ │ Durable │ │ Vectorize│ │ │
│ │ │ │ │ Objects │ │ │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ │ Data Layer │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Workers
Router Worker
Routes requests to appropriate backends:
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
// Route API requests
if (url.pathname.startsWith('/api/v1/')) {
return env.API_GATEWAY.fetch(request);
}
// Serve static assets from R2
if (url.pathname.startsWith('/static/')) {
return env.ASSETS.fetch(request);
}
// WebSocket connections
if (request.headers.get('Upgrade') === 'websocket') {
return handleWebSocket(request, env);
}
return new Response('Not Found', { status: 404 });
}
};
Auth Worker
Validates tokens at the edge:
async function validateToken(request: Request, env: Env): Promise<TokenPayload | null> {
const token = request.headers.get('Authorization')?.replace('Bearer ', '');
if (!token) return null;
// Check token cache
const cached = await env.TOKEN_CACHE.get(token);
if (cached) return JSON.parse(cached);
// Validate with auth service
const response = await env.AUTH_SERVICE.fetch('/validate', {
method: 'POST',
body: JSON.stringify({ token }),
});
if (!response.ok) return null;
const payload = await response.json();
// Cache for 5 minutes
await env.TOKEN_CACHE.put(token, JSON.stringify(payload), {
expirationTtl: 300,
});
return payload;
}
Rate Limiter
Protects against abuse:
async function rateLimit(request: Request, env: Env): Promise<Response | null> {
const ip = request.headers.get('CF-Connecting-IP');
const key = `rate:${ip}`;
const id = env.RATE_LIMITER.idFromName(key);
const limiter = env.RATE_LIMITER.get(id);
const response = await limiter.fetch(request);
if (response.status === 429) {
return new Response('Too Many Requests', {
status: 429,
headers: {
'Retry-After': response.headers.get('Retry-After') || '60',
},
});
}
return null;
}
OlympusEdge (On-Premise)
Overview
OlympusEdge provides offline-capable restaurant operations:
┌─────────────────────────────────────────────────────────────────┐
│ Restaurant Location │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ OlympusEdge Device │ │
│ │ │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Local │ │ Sync │ │ Local │ │ │
│ │ │ API │ │ Engine │ │ Database │ │ │
│ │ └────┬─────┘ └────┬─────┘ └────┬─────┘ │ │
│ │ │ │ │ │ │
│ │ └─────────────┼─────────────┘ │ │
│ │ │ │ │
│ └─────────────────────┼────────────────────────────────────┘ │
│ │ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ POS │ │ KDS │ │ Kiosk │ │
│ │ Terminal │ │ Display │ │ │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└────────────────────────┼────────────────────────────────────────┘
│
▼
Cloud Sync (when online)
Offline Capabilities
info
OlympusEdge maintains full POS functionality during internet outages. Card payments use offline authorization tokens with settlement queued for when connectivity returns. Cash transactions operate normally. The sync engine automatically reconciles all queued operations on reconnect.
| Feature | Offline Support | Sync Strategy |
|---|---|---|
| Order Creation | Full | Queue and sync |
| Payment (card) | Limited (offline auth) | Settle when online |
| Payment (cash) | Full | Sync when online |
| Menu Display | Full (cached) | Periodic refresh |
| Inventory | Full (local tracking) | Reconcile on sync |
| Reports | Limited (local data) | Full sync required |
Data Synchronization
pub struct SyncEngine {
local_db: SqlitePool,
cloud_client: CloudClient,
sync_queue: VecDeque<SyncOperation>,
}
impl SyncEngine {
pub async fn sync(&mut self) -> Result<SyncResult> {
// 1. Push local changes
while let Some(op) = self.sync_queue.pop_front() {
match self.cloud_client.push(op).await {
Ok(_) => continue,
Err(e) if e.is_conflict() => {
self.resolve_conflict(op).await?;
}
Err(e) => {
self.sync_queue.push_front(op);
return Err(e);
}
}
}
// 2. Pull cloud changes
let changes = self.cloud_client.pull_since(self.last_sync).await?;
for change in changes {
self.apply_change(change).await?;
}
// 3. Update sync timestamp
self.last_sync = Utc::now();
Ok(SyncResult::Success)
}
}
Conflict Resolution
| Conflict Type | Resolution |
|---|---|
| Order update | Last-write wins with merge |
| Inventory count | Cloud authoritative |
| Menu changes | Cloud authoritative |
| Payment | Cloud authoritative |
Edge AI (Workers AI)
Use Cases
| Feature | Model | Latency |
|---|---|---|
| Intent Classification | Llama Scout | < 50ms |
| Menu Search | Text Embeddings | < 20ms |
| Image Recognition | Vision Models | < 100ms |
Example: Intent Classification
async function classifyIntent(text: string, env: Env): Promise<Intent> {
const response = await env.AI.run('@cf/meta/llama-2-7b-chat-int8', {
prompt: `Classify the customer intent: "${text}"
Categories: order, question, complaint, modification, cancel
Intent:`,
max_tokens: 10,
});
return parseIntent(response.response);
}
Data at the Edge
KV Store
Fast key-value storage for:
- Session tokens
- Feature flags
- Rate limit counters
- Cached responses
Durable Objects
Stateful edge compute for:
- WebSocket connections
- Rate limiting state
- Shopping cart state
- Real-time collaboration
R2 Storage
Object storage for:
- Static assets
- Menu images
- Receipt PDFs
- Backup data
Deployment
Worker Deployment
# wrangler.toml
name = "olympus-edge"
main = "src/index.ts"
compatibility_date = "2026-01-01"
[env.production]
routes = [
{ pattern = "api.olympuscloud.ai/*", zone_name = "olympuscloud.ai" }
]
[[kv_namespaces]]
binding = "TOKEN_CACHE"
id = "xxx"
[[durable_objects.bindings]]
name = "RATE_LIMITER"
class_name = "RateLimiter"
[[r2_buckets]]
binding = "ASSETS"
bucket_name = "olympus-assets"
OlympusEdge Deployment
# Install on edge device
curl -fsSL https://edge.olympuscloud.ai/install.sh | bash
# Configure
olympus-edge config set --location-id loc-xyz789
olympus-edge config set --api-key $API_KEY
# Start
olympus-edge start
Monitoring
Edge Metrics
| Metric | Description |
|---|---|
edge.requests | Total edge requests |
edge.latency | Edge processing time |
edge.cache.hit_rate | Cache effectiveness |
edge.errors | Error rate |
OlympusEdge Metrics
| Metric | Description |
|---|---|
edge.sync.queue_size | Pending sync operations |
edge.sync.last_success | Last successful sync |
edge.offline.duration | Time since last online |
edge.local.orders | Orders pending sync |
Related Documentation
- Architecture Overview - Platform architecture
- Edge Workers Deployment - Deployment guide
- WebSocket API - Real-time connections