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

# Lightweight Pattern

> Deploy cost-effective Fjall infrastructure on AWS Fargate Spot for simple, low-traffic applications.

## Overview

The Lightweight pattern uses Fargate Spot to run your containers at a significant discount compared to on-demand Fargate pricing. It is a good fit for simple applications, internal tools, and workloads that can tolerate occasional interruptions.

## What's Included

```bash theme={null}
fjall create app --type lightweight
```

Creates:

* **ECS on Fargate Spot** (up to 70% cost savings)
* **RDS Instance** in single AZ
* **Application Load Balancer**
* **Basic monitoring**

## Architecture

```
┌─────────────────┐
│      ALB        │ (2 AZ)
└────────┬────────┘
         |
┌────────┴────────┐
│  ECS Fargate    │ (FARGATE_SPOT, 1 task)
│  Spot           │ (256 CPU, 512 MiB)
└────────┬────────┘
         |
┌────────┴────────┐
│  RDS Instance   │ (2 AZ)
└─────────────────┘
```

## Generated Infrastructure

```typescript theme={null}
#!/usr/bin/env node

import {
  App,
  DatabaseFactory,
  ComputeFactory,
  getConfig,
} from "@fjall/components-infrastructure";

const appName = "simple";
const app = App.getApp(appName);

app.addTags({
  "fjall:costAllocation:owner": "engineering",
});

const simpleStorage = app.addDatabase(
  DatabaseFactory.build("SimpleStorage", {
    type: "Instance",
    databaseName: "SimpleDatabase",
  }),
);

app.addCompute(
  ComputeFactory.build("SimpleCompute", {
    type: "ecs",
    ecrRepository: app.getDefaultContainerRegistry(),
    services: [
      {
        name: "app",
        capacityProvider: "FARGATE_SPOT",
        cpu: 256,
        memoryLimitMiB: 512,
        desiredCount: 1,
        scaling: {
          maxCapacity: 3,
        },
        containers: [
          {
            port: 3000,
            environment: {
              ENVIRONMENT: getConfig().environment,
              DATABASE_HOST: simpleStorage.getHostEndpoint(),
              DATABASE_PORT: `${simpleStorage.getHostPort()}`,
              DATABASE_NAME: simpleStorage.getDatabaseName(),
            },
            secretsImport: {
              DATABASE_PASSWORD: simpleStorage
                .getCredentials()
                .getImport("password"),
            },
          },
        ],
      },
    ],
  }),
);
```

## Specifications

### Compute (ECS on Fargate Spot)

* **Capacity provider**: FARGATE\_SPOT (up to 70% savings vs on-demand)
* **CPU**: 256 units (0.25 vCPU)
* **Memory**: 512 MiB
* **Tasks**: 1 (scales up to 3)
* **Availability**: 2 AZ

### Database (RDS Instance)

* **Engine**: PostgreSQL 17.5
* **Instance**: t4g.small
* **Storage**: 20 GB gp3
* **Backup**: 7-day retention
* **Multi-AZ**: No (single AZ)

### Networking

* **VPC**: 2 AZ setup
* **Subnets**: Public and private
* **Load Balancer**: Basic ALB
* **NAT**: 1 NAT gateway

## Cost Comparison

| Pattern         | Monthly Cost | Availability                  |
| --------------- | ------------ | ----------------------------- |
| Tinkerer        | \$0\*        | 2 AZ, EC2 direct access       |
| **Lightweight** | **\~\$35**   | **2 AZ, Fargate Spot**        |
| Standard        | \~\$86       | Multi-AZ capable              |
| Resilient       | \~\$150+     | Multi-AZ, enhanced monitoring |

\* Tinkerer is \$0 only within AWS free-tier limits. Data-transfer and over-limit usage incur charges.

## Use Cases

**Perfect for:**

* Internal tools
* Development environments
* Low-traffic websites
* Simple APIs
* Prototypes going to production
* Cost-sensitive projects

**Not suitable for:**

* High availability requirements (Spot tasks can be interrupted)
* Mission-critical applications
* High traffic loads
* Multi-region needs

## Key Differences from Standard

| Feature           | Lightweight   | Standard                     |
| ----------------- | ------------- | ---------------------------- |
| Capacity provider | FARGATE\_SPOT | FARGATE                      |
| CPU               | 256           | 512                          |
| Memory            | 512 MiB       | 1024 MiB                     |
| Default tasks     | 1             | 2                            |
| Max tasks         | 3             | 5                            |
| Interruption risk | Yes (Spot)    | No                           |
| Cost              | \~40% cheaper | Full price, full reliability |

## Customisation

### Upgrading to On-Demand Fargate

If you need guaranteed capacity, switch the capacity provider:

```typescript theme={null}
app.addCompute(
  ComputeFactory.build("SimpleCompute", {
    type: "ecs",
    services: [
      {
        name: "app",
        capacityProvider: "FARGATE", // Switch from FARGATE_SPOT
        cpu: 256,
        memoryLimitMiB: 512,
      },
    ],
  }),
);
```

### Upgrading Database

```typescript theme={null}
const simpleStorage = app.addDatabase(
  DatabaseFactory.build("SimpleStorage", {
    type: "Instance",
    databaseName: "SimpleDatabase",
    instanceType: "t4g.medium", // More power
  }),
);
```

## Monitoring

Basic CloudWatch monitoring includes:

* ECS service health
* RDS basic metrics
* ALB request count
* Application logs

## Upgrade Path

### To Standard Pattern

1. Change capacity provider to `FARGATE`
2. Increase CPU to 512 and memory to 1024 MiB
3. Increase desired count to 2 for high availability

### To Resilient Pattern

* Migrate database to Aurora
* Increase task count and scaling limits
* Add KMS encryption

## Security Considerations

### Network Security

* Private subnets for database
* Security groups with minimal rules
* No direct internet access for compute

### Data Security

* Encryption at rest enabled
* TLS for data in transit
* Secrets in AWS Secrets Manager

## Best Practices

1. **Start with Lightweight** for new projects that do not need guaranteed uptime
2. **Monitor Spot interruptions** via CloudWatch
3. **Regular backups** even with automation
4. **Plan for growth** but do not over-provision
5. **Use caching** to maximise performance
6. **Keep it simple**. Complexity adds cost

## Next Steps

<CardGroup cols={2}>
  <Card title="Deploy an Application" icon="rocket" href="/deployment/deploy-application">
    Deploy your Lightweight application to AWS
  </Card>

  <Card title="Add Resources" icon="plus" href="/deployment/add-resources">
    Add databases, storage, and more to your application
  </Card>

  <Card title="Compute Factory" icon="server" href="/patterns/compute-factory">
    Customise the compute configuration
  </Card>

  <Card title="Storage Factory" icon="box" href="/patterns/storage-factory">
    Configure S3 storage for your application
  </Card>
</CardGroup>
