Skip to content

Proposal: Migrate Core Storage to Cloudflare D1 + KV Cache #246

@miantiao-me

Description

@miantiao-me

Background

The current KV-only architecture has reached its limits regarding feature expansion.
Many requested features (like sorting by time or filtering by domain) are becoming impossible to implement elegantly because KV lacks native query capabilities.

To support the long-term development of Sink, I plan to migrate the core data storage to Cloudflare D1 (SQLite).

What problems will this solve?

By introducing SQL capabilities, we can resolve several long-standing issues at once:

  • Sorting & Pagination
    Native support for ORDER BY created_at, finally allowing the dashboard to show the newest links first.

  • Advanced Filtering
    Support for filtering by domain, expiration time, and similar attributes.

  • Flexibility
    Remove key format restrictions (supporting slugs with /)
    and enable features like tagging.

Architecture: D1 + KV Cache

To ensure we don't sacrifice redirection speed, I plan to use a D1 + KV (Cache) hybrid approach:

  • Management (Admin / API)
    Reads and writes go to D1 as the Source of Truth, providing full sorting and filtering capabilities.

  • Redirection
    Prioritizes reading from KV Cache (synced when writing to D1) to maintain extreme performance and low latency.

Impact

  1. Breaking Change
    The current KV cursor-based pagination API will be deprecated in favor of SQL-based pagination.

  2. Data Migration
    A migration script will be provided to import existing KV data into D1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions