Rule Persistence
By default, Ordo stores rules in memory. Enable file-based persistence to retain rules across restarts.
Enable Persistence
Use the --rules-dir flag to specify a directory for rule storage:
bash
ordo-server --rules-dir ./rulesHow It Works
When persistence is enabled:
- Startup: Rules are loaded from
.json,.yaml, and.ymlfiles in the directory - Create/Update: Rules are saved to the directory when created or updated via API
- Delete: Rule files are removed when deleted via API
Directory Structure
rules/
├── discount-check.json
├── loan-approval.yaml
├── fraud-detection.json
└── .versions/
├── discount-check/
│ ├── v1_1704700000.json
│ └── v2_1704800000.json
└── loan-approval/
└── v1_1704700000.yamlFile Formats
JSON Format
json
{
"config": {
"name": "discount-check",
"version": "1.0.0",
"entry_step": "check_vip"
},
"steps": {
"check_vip": {
"id": "check_vip",
"type": "decision",
"branches": [{ "condition": "user.vip == true", "next_step": "vip_discount" }],
"default_next": "normal_discount"
}
}
}YAML Format
yaml
config:
name: discount-check
version: '1.0.0'
entry_step: check_vip
steps:
check_vip:
id: check_vip
type: decision
branches:
- condition: 'user.vip == true'
next_step: vip_discount
default_next: normal_discount
vip_discount:
id: vip_discount
type: terminal
result:
code: VIP
message: '20% discount applied'File Naming
- File name becomes the rule name (without extension)
discount-check.json→ rule name:discount-check- If multiple files have the same base name, JSON takes priority over YAML
Health Check
The health endpoint shows storage mode:
bash
curl http://localhost:8080/healthjson
{
"status": "healthy",
"version": "0.1.0",
"storage": {
"mode": "persistent",
"rules_dir": "./rules",
"rules_count": 3
}
}Best Practices
- Use version control: Keep your rules directory in Git
- Organize by domain: Use subdirectories for different rule categories
- Prefer YAML for readability: YAML is easier to read and edit manually
- Use JSON for programmatic access: JSON is better for API responses
- Backup regularly: Implement backup strategies for production
Troubleshooting
Rules not loading
- Check file permissions
- Verify JSON/YAML syntax
- Check server logs for parsing errors
Changes not persisting
- Verify
--rules-diris specified - Check directory write permissions
- Ensure disk space is available
Startup errors
bash
# Check for syntax errors
cat rules/my-rule.json | jq .
# Validate YAML
python -c "import yaml; yaml.safe_load(open('rules/my-rule.yaml'))"