> ## Documentation Index
> Fetch the complete documentation index at: https://docs.go-mizu.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Production

> Deploy mobile backends to production with best practices.

This guide covers production deployment considerations for Mizu mobile backends.

## Environment Configuration

```go theme={null}
type Config struct {
    Port            string
    Environment     string
    MinAppVersion   string
    MaintenanceMode bool
}

func LoadConfig() *Config {
    return &Config{
        Port:            getEnv("PORT", "3000"),
        Environment:     getEnv("ENVIRONMENT", "development"),
        MinAppVersion:   getEnv("MIN_APP_VERSION", "1.0.0"),
        MaintenanceMode: getEnv("MAINTENANCE_MODE", "false") == "true",
    }
}
```

## API Versioning Strategy

### Version Header

```go theme={null}
app.Use(mobile.VersionMiddleware(mobile.VersionOptions{
    Header:     "X-API-Version",
    Supported:  []mobile.Version{{3, 0}, {2, 0}},
    Deprecated: []mobile.Version{{2, 0}},
    Default:    mobile.Version{Major: 3},
}))
```

### Deprecation Timeline

1. **Month 1**: Release v3, mark v2 as deprecated
2. **Month 2**: Log v2 usage, notify users
3. **Month 3**: Raise minimum app version
4. **Month 4**: Remove v2 support

## Performance Optimization

### Response Caching

```go theme={null}
app.Use(cache.New(cache.Config{
    Expiration: 5 * time.Minute,
    KeyGenerator: func(c *mizu.Ctx) string {
        device := mobile.DeviceFromCtx(c)
        return c.Path() + ":" + device.Platform.String()
    },
}))
```

### Gzip Compression

```go theme={null}
app.Use(compress.New(compress.Config{
    Level: compress.LevelBestSpeed,
}))
```

## Monitoring

### Request Logging

```go theme={null}
app.Use(func(next mizu.Handler) mizu.Handler {
    return func(c *mizu.Ctx) error {
        device := mobile.DeviceFromCtx(c)
        start := time.Now()

        err := next(c)

        log.Info("request",
            "path", c.Path(),
            "method", c.Method(),
            "status", c.Response().StatusCode,
            "duration", time.Since(start),
            "platform", device.Platform,
            "app_version", device.AppVersion,
        )

        return err
    }
})
```

### Version Distribution

```go theme={null}
// Track app version distribution
metrics.RecordAppVersion(device.Platform, device.AppVersion)
```

## Health Checks

```go theme={null}
app.Get("/health", func(c *mizu.Ctx) error {
    return c.JSON(200, map[string]any{
        "status": "healthy",
        "time":   time.Now().UTC(),
    })
})

app.Get("/ready", func(c *mizu.Ctx) error {
    // Check database, cache, etc.
    if err := db.Ping(); err != nil {
        return c.JSON(503, map[string]string{
            "status": "not ready",
            "error":  "database unavailable",
        })
    }
    return c.JSON(200, map[string]string{"status": "ready"})
})
```

## Graceful Shutdown

```go theme={null}
func main() {
    app := mizu.New()
    setupRoutes(app)

    // Graceful shutdown
    app.ListenWithShutdown(":3000", 30*time.Second)
}
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Security" href="/mobile/security" icon="shield">
    Security best practices
  </Card>

  <Card title="Troubleshooting" href="/mobile/troubleshooting" icon="bug">
    Debug common issues
  </Card>
</CardGroup>
