# Deploy Functions Globally in Seconds

> Write TypeScript functions with full type safety and deploy to edge locations worldwide. Zero cold starts with automatic scaling.

Canonical: https://functions.do/

## In code

```typescript
import { $, db, ai } from 'sdk.do'

// Order processing function with fraud detection
export async function processOrder(order: any) {
  const fraudCheck = await ai.generate({
    prompt: `Analyze order for fraud: ${JSON.stringify(order)}`,
    schema: $.Security.analyzes.FraudRisk
  })

  if (fraudCheck.riskScore > 0.8) throw new Error('High fraud risk')

  await db.update('orders', order.id, { status: 'processing' })
  return { ...order, validated: true }
}

// Webhook handler with semantic routing
export async function handleWebhook(webhook: any) {
  if (webhook.source === 'stripe') return processPayment(webhook.data)
  if (webhook.source === 'shopify') return syncInventory(webhook.data)
  return { status: 'ignored' }
}
```

## Frequently asked questions

### How does functions.do achieve zero cold starts?

Functions run on Cloudflare Workers using V8 isolates that start in <1ms vs 100-1000ms for containers. Every function stays warm at the edge with automatic distribution across 300+ locations.

### What are the execution limits?

128MB memory and 50ms CPU time with unlimited concurrent executions covers 99% of use cases like API handlers and webhooks. Use queues or scheduled functions for long-running tasks.

### How does pricing work at scale?

Pay only for CPU time used per millisecond—first 100K requests daily free, then $0.50/million requests with no idle charges or minimums. Example: 10M requests/month at 5ms average = $47/month.

### Can functions access databases and external APIs?

Yes, with built-in connectors for PostgreSQL, MySQL, MongoDB, Redis, and Cloudflare D1/R2/KV/Durable Objects. HTTP fetch works for any external API with automatic retries and caching.

### How do I handle errors and observability?

Automatic error capturing with stack traces, configurable retry policies, and dead letter queues for failed invocations. Real-time logs, distributed tracing, and metrics dashboards show invocations, errors, and latency.

## Part of Platform.do

functions.do is one of the primitives of Platform.do, in the Workflows layer (triggers, steps and functions). Every .do shares one grammar, Business-as-Code, and one SDK.

- What is Business-as-Code? https://platform.do/business-as-code
- Platform.do: https://platform.do/
- Docs: https://docs.platform.do
