# How to automate data archiving in Bubble.io to optimize app performance: Step-by

- Tool: Bubble
- Difficulty: Beginner
- Time required: 15-20 min
- Compatibility: All Bubble plans
- Last updated: March 2026

## TL;DR

Automate data archiving in Bubble by moving old records to archive data types via scheduled backend workflows, reducing active database size for faster searches, and retrieving archived data on demand. This keeps your app performant as data grows without losing historical records.

## Overview: Automating Data Archiving in Bubble

This tutorial shows you how to move old records to archive tables using scheduled backend workflows, reducing the size of your active database for faster searches and lower workload unit consumption.

## Before you start

- A Bubble account with data that grows over time
- Understanding of Bubble data types and backend workflows
- Familiarity with scheduled workflows
- Basic knowledge of Bubble searches

## Step-by-step guide

### 1. Create archive data types

For each data type you want to archive, create a mirror type prefixed with Archive_. For example, Archive_Order with the same fields as Order plus an archived_date field. This keeps archived records separate from active ones, so active searches remain fast.

**Expected result:** Archive data types exist mirroring your active tables.

### 2. Build the archiving backend workflow

Create a backend workflow called archive_old_records. Search for records meeting your archive criteria: e.g., Orders where status = Completed and Date created < 90 days ago. For each record, create a corresponding Archive_Order record with all field values copied, set archived_date to Current date/time, then delete the original Order. Use a recursive workflow to process records in batches of 50 to avoid timeout.

> Pro tip: Process in batches of 50 with a 1-second pause between batches to stay within Bubble's execution limits.

**Expected result:** Old records are copied to archive tables and removed from active tables.

### 3. Schedule the archiving workflow

Schedule the archive_old_records workflow to run weekly or monthly using the Schedule API workflow action. Set the scheduled date to next Sunday at 2 AM (or another low-traffic time). At the end of the workflow, schedule itself to run again in 7 days for weekly archiving. This creates a self-perpetuating schedule.

**Expected result:** Archiving runs automatically on a weekly or monthly schedule.

### 4. Build an archive retrieval interface

Create an admin page where staff can search archived records. Add a Repeating Group with Archive_Order as the type, with filters for date range and customer. Add a Restore button that creates a new Order from the archive record and deletes the archive copy. For automated archiving strategies with compliance requirements, consider working with RapidDev.

**Expected result:** Staff can search and optionally restore archived records when needed.

## Complete code example

File: `Workflow summary`

```text
DATA ARCHIVING — WORKFLOW SUMMARY
===================================

DATA TYPES:
  Order (active)
    - customer, amount, status, items, created_date
  Archive_Order (archive)
    - Same fields as Order
    - archived_date (date)

BACKEND WORKFLOW: archive_old_records
  Step 1: Search for Orders
    status = Completed
    Date created < Current date - 90 days
    :items until #50 (batch size)
  Step 2: For each Order in batch:
    Create Archive_Order (copy all fields)
    Delete original Order
  Step 3: If more records exist (count > 0)
    Schedule archive_old_records again in 1 second
  Step 4: If no more records
    Schedule archive_old_records for next week

SCHEDULE:
  Runs: weekly, Sunday 2:00 AM
  Self-scheduling: reschedules at end of run

ARCHIVE RETRIEVAL:
  Admin page with:
    - Date range filter
    - Customer search
    - Repeating Group of Archive_Orders
    - Restore button per record
```

## Common mistakes

- **Deleting records without archiving them first** — Deleted data is gone permanently. You lose historical records needed for reporting or auditing Fix: Always create the archive copy and verify it was saved before deleting the original.
- **Archiving too many records in a single workflow run** — Processing thousands of records at once causes the workflow to timeout Fix: Process records in batches of 50 with recursive scheduling between batches.
- **Not including all fields in the archive data type** — Missing fields mean archived records are incomplete and potentially useless for historical analysis Fix: Mirror every field from the active data type in the archive type. Add the archived_date field as well.

## Best practices

- Create archive types that mirror all fields from active types
- Process records in batches to avoid workflow timeouts
- Schedule archiving during low-traffic hours
- Archive based on clear criteria (age + status)
- Provide a retrieval interface for accessing archived data
- Test archiving on a small batch before running on full data
- Monitor database size in Settings after archiving runs

## Frequently asked questions

### How much data should I archive?

Archive records older than 60-90 days that are in a final status (Completed, Cancelled). Keep active and recent records in the main tables.

### Will archiving reduce my workload units?

Yes. Searches on smaller tables are faster and consume fewer WUs. The improvement is most noticeable when you have thousands of records.

### Can I still run reports on archived data?

Yes. Run reports against the archive tables. For combined reports, you may need to query both active and archive tables and merge results.

### Can RapidDev help with database optimization?

Yes. RapidDev specializes in Bubble development and can help implement comprehensive data management strategies including archiving, optimization, and migration.

### What if I need to restore archived records?

Build a restore workflow that creates a new record in the active table from the archive record, then deletes the archive copy.

---

Source: https://www.rapidevelopers.com/bubble-tutorial/automate-data-archiving-optimize-performance-bubble
© RapidDev — https://www.rapidevelopers.com/bubble-tutorial/automate-data-archiving-optimize-performance-bubble
