Skip to main content

CRUD Application

A simple FastAPI CRUD service for testing systemg service management capabilities.

Features demonstrated

  • Service management with sysg start and sysg stop
  • Automatic recovery from failures
  • Controlled service restarts
  • Modern Python with FastAPI and uvicorn
  • Package management with uv

Configuration

File logging is enabled here so sysg logs --service fastapi_server works out of the box. For production services whose output is already collected elsewhere, set logs.sink: none. Summary status snapshots keep sysg status and sysg inspect responsive by reading current persisted state while avoiding detailed runtime process collection per command.

Application code

main.py

Dependencies

Create pyproject.toml:

Run it

API endpoints

  • GET / - Health check
  • POST /todos - Create a new todo
  • GET /todos - List all todos
  • GET /todos/{id} - Get a specific todo
  • PUT /todos/{id} - Update a todo
  • DELETE /todos/{id} - Delete a todo
  • GET /chaos - Random failure endpoint (70% failure rate)

Testing

Run the test script to verify all endpoints:
The test script will:
  1. Create a new todo
  2. Read all todos
  3. Update the todo
  4. Get a specific todo
  5. Test the chaos endpoint (demonstrates recovery)
  6. Delete the todo

Operations

Stop the service

View logs

Check status

Example usage

Create a Todo

List Todos

Update a Todo

Test chaos endpoint

What happens

  1. Service starts with sysg start and serves the API on port 8888
  2. In-memory storage using Python dict for simplicity
  3. Chaos endpoint randomly fails to demonstrate recovery capabilities
  4. Automatic restarts when service crashes (up to 10 restarts with 5s backoff)
  5. Restarts replace the fixed-port instance; use blue-green slots when an application requires zero-downtime updates

Interactive API docs

FastAPI provides automatic interactive documentation at:
  • Swagger UI: http://localhost:8888/docs
  • ReDoc: http://localhost:8888/redoc

See also