# LotusCloud Storage Architecture

## Overview

LotusCloud provides three storage types similar to AWS S3/EBS/EFS, built on Ceph.

## Storage Types

| Type | Technology | Use Case | AWS Equivalent |
|------|-----------|----------|---------------|
| Object Storage | Ceph RGW | Files, images, backups | S3 |
| Block Storage | Ceph RBD | VM disks, DB volumes | EBS |
| File Storage | CephFS | Shared filesystems, K8s PV | EFS |

## Ceph Architecture

```
Ceph Cluster
   │
   ├── MON x3 (monitor, quorum)
   ├── MGR x2 (management, dashboard)
   ├── OSD x N (storage daemons)
   └── RGW x2 (S3 gateway, load balanced)
```

### Object Storage (S3-Compatible)

```
Client
   │
   ▼ (S3 API)
   │
Ceph RGW (load balanced)
   │
   ▼
Ceph RADOS
   │
   ├── OSD-1 (replica 1)
   ├── OSD-2 (replica 2)
   └── OSD-3 (replica 3)
```

Features:
- S3-compatible API
- Bucket ACL / Bucket Policy
- Versioning
- Lifecycle rules (transition to cold, delete after N days)
- Cross-region replication
- Server-side encryption (AES-256)
- Multipart upload
- Pre-signed URLs

### Block Storage

```
VM
   │
   ▼ (block device /dev/vdb)
   │
Ceph RBD (RADOS Block Device)
   │
   ▼
Ceph RADOS (replicated)
```

Features:
- Thin provisioning
- Snapshots
- Clone from snapshot
- Resize online
- Encryption at rest
- QoS (IOPS limits)

### File Storage

```
Multiple VMs / K8s Pods
   │
   ▼ (POSIX mount)
   │
CephFS
   │
   ▼
Ceph RADOS
```

Features:
- POSIX-compliant
- Multi-mount (shared across VMs)
- Kubernetes PersistentVolume
- Snapshots

## Storage Tiers

| Tier | Media | IOPS | Latency | Price |
|------|-------|------|---------|-------|
| Premium | NVMe SSD | > 50,000 | < 0.5ms | $$$ |
| Standard | SSD | > 10,000 | < 2ms | $$ |
| Archive | HDD | > 1,000 | < 10ms | $ |

## Replication & Durability

```
Replication Factor: 3 (default)

Data written to 3 OSDs across different failure domains:
  OSD-1 (rack-1)
  OSD-2 (rack-2)
  OSD-3 (rack-3)

Durability target: 99.999999999% (11 nines)
```

### Erasure Coding (for archive tier)

```
EC profile: k=4, m=2
  4 data chunks + 2 parity chunks
  Can lose 2 chunks and still recover
  Storage overhead: 1.5x (vs 3x for replication)
```

## Cross-Region Replication

```
Site A (VN-South)                 Site B (VN-North)
┌──────────────┐                 ┌──────────────┐
│ Ceph Cluster │ ──async sync──► │ Ceph Cluster │
│ (primary)    │                 │ (secondary)  │
└──────────────┘                 └──────────────┘
```

For backup/DR:
- Object storage: RGW multisite sync
- Block storage: RBD mirroring
- Async replication (RPO < 15 min)

## Backup Architecture

```
Backup Types:
  Full backup     → Complete copy
  Incremental     → Only changed blocks since last backup
  Snapshot        → Point-in-time frozen state
  
Backup Targets:
  Same zone       → Fast restore
  Cross-zone      → HA within region
  Cross-region    → DR between regions

Backup API:
  POST /v1/backup/create          Create backup
  POST /v1/backup/restore         Restore backup  
  GET  /v1/backup/list            List backups
  POST /v1/backup/policy          Set backup policy
```

## Storage API

```
# Object Storage (S3-compatible)
PUT    /bucket/object              Upload object
GET    /bucket/object              Download object
DELETE /bucket/object              Delete object
HEAD   /bucket/object              Object metadata

# Block Storage
POST   /v1/storage/volumes         Create volume
GET    /v1/storage/volumes         List volumes
DELETE /v1/storage/volumes/{id}    Delete volume
POST   /v1/storage/volumes/{id}/attach     Attach to VM
POST   /v1/storage/volumes/{id}/detach     Detach from VM
POST   /v1/storage/volumes/{id}/resize     Resize volume
POST   /v1/storage/volumes/{id}/snapshot   Create snapshot

# File Storage
POST   /v1/storage/filesystems    Create filesystem
GET    /v1/storage/filesystems    List filesystems
```

## Data Lifecycle Management

```json
{
  "bucket": "logs",
  "rules": [
    {
      "name": "move-to-archive",
      "prefix": "access-logs/",
      "action": "transition",
      "target_tier": "archive",
      "after_days": 30
    },
    {
      "name": "delete-old-logs",
      "prefix": "access-logs/",
      "action": "delete",
      "after_days": 365
    }
  ]
}
```
