# Data and storage

> What Koil stores, what it only passes through, and for how long.

Koil stores what it needs to run your integration, and passes platform content through, keeping it only as long as delivering it needs.

## What Koil stores

-   **Publish request ledger** — each `pub_…` entry's status, platform references, schedule, `metadata`, and timestamps.
-   **Idempotency records** — the operation, key, a keyed hash of the request, and the response it answered with, encrypted. Kept for 24 hours.
-   **Ingestion state** — the cursors, watermarks, and rate-limit counters needed to collect events, kept while the Profile and its collection remain active.
-   **Media** — `med_…` objects you upload or have Koil fetch, until you delete them. The file itself is kept only long enough to prepare publishes: a `mediaId` is publishable for 24 hours after creation, and each publish keeps its own prepared copy until it finishes.
-   **Platform content waiting to become events** — each webhook delivery a platform sends Koil, held until its events are published, then deleted. One that can't be processed is kept so it can be investigated, and deleted no later than 24 hours after it arrived. This is what lets delivery survive an outage on either side.
-   **Delivered events** — the event delivery service logs each delivery and its attempts, so a delivery can be [retried](https://docs.koil.co/guides/subscribe-to-events#delivery-history-and-retries). A delivered event stays in that log for the service's log retention; the API's attempt history reports each delivery's outcome, never the event's body.
-   **Your configuration** — Apps (the OAuth client secret is write-only: no read returns it), Connections and their platform credentials, Profiles, and Event Destinations.
-   **Connect Sessions** — each `cs_…` session's App, `clientUserId`, `returnUrl`, status and outcome, deleted a day after it expires, and with its App.
-   **Backups** — Koil's database can be restored to any point in the last six days, so a record Koil deletes stays recoverable from backups for up to six days.

## Credentials

Platform credentials are kept only while something can still use them, and deleted with everything that depends on them:

-   **Deleting a Connection** deletes its credential, the credentials Koil derived from it (such as a Facebook Page token), and its Profiles.
-   **Deleting an App** deletes your app's client secret and any credential still stored under it. It is refused while a Connection you can see still uses it.
-   **Deleting your Organization** deletes every Profile, Connection, and App it had, then everything else Koil stores for it: the publish request ledger, media, backfill runs, idempotency records, usage counts, and billing account. Publishes still waiting for their schedule are cancelled, which deletes their prepared media. Invoices stay with Stripe.
-   **An end user revoking access** makes the platform refuse its token at the next call or renewal, and Koil makes the Connection `invalid`, announced by [`connection.updated`](https://docs.koil.co/events#connection.updated), and deletes its credentials at once. A Connection still `invalid` six days later is deleted, well inside the seven days YouTube allows after a revocation. Re-authorizing the Connection keeps it.
-   **An end user losing access to one profile** (their role on a Facebook Page) makes that Profile `invalid`, announced by [`profile.updated`](https://docs.koil.co/events#profile.updated); its credential is deleted at once, and the profile itself six days later unless the user connects again with access restored.

A revocation's deletions emit `profile.deleted` and `connection.deleted`, as deleting through the API does.

## What Koil does not store

Platform content observed through a Profile — posts, comments, messages, mentions, and moderation outcomes — is delivered as events and discarded; a webhook delivery that carried it is deleted once its events are published, or 24 hours after it arrived if it can't be processed, and the events stay in the delivery log described above. Content reads go to the platform each time. If your product needs history, persist it from the events you receive; a [backfill request](https://docs.koil.co/guides/backfill) can re-deliver what is still on the platform.

A publish's own payload is held only while the publish runs and for two days after it ends, in workflow state encrypted at rest, and is never copied into Koil's database.
