Markdown Editor

RFC Template (Request for Comments)

RFC proposal: summary, motivation, guide-level explanation, detailed design, drawbacks, alternatives, prior art, rollout, decision

Perangkat Lunak & RekayasaStandarRust RFC process (section structure)rfc

Cara menggunakan: Use for changes that affect other teams, public interfaces or are hard to reverse. Write the motivation with data first and name the decider and review deadline in the header. The main pitfall is debating solutions before reviewers agree on the problem, and not recording why an RFC was accepted or rejected.

Pratinjau

RFC-[NNNN]: [Proposal title]

Request for Comments for a significant change to a product, API, platform or engineering practice. The section order follows the open-source RFC pattern popularised by the Rust project (summary, motivation, guide-level explanation, detailed design, drawbacks, alternatives, prior art, unresolved questions), with rollout and a review log added for teams. Replace every [bracketed] value and every row marked Example.

FieldValue
RFC number[RFC-0042]
Title[Proposal title]
Author(s)[@name]
Decider[@name or forum, for example Architecture Review Board]
Reviewers[@name, @name, team-x]
Status[Draft / In review / Final comment period / Accepted / Rejected / Withdrawn / Implemented]
CreatedYYYY-MM-DD
Review deadlineYYYY-MM-DD
Discussion[link to thread or pull request]
Tracking issue[link]

1. Summary

Example: Introduce cursor-based pagination for all list endpoints of the public API (GET /v2/*), replacing offset pagination. Clients receive an opaque next_cursor and pass it back to fetch the next page. Offset parameters keep working for 12 months and then return an error.

2. Motivation

Example: Offset pagination causes three recurring problems:

  • Deep pages are slow: OFFSET 50000 queries take 2.4 s at p95 and caused two incidents last quarter.
  • Clients see duplicates or gaps when records are inserted while they page.
  • Large customers export data by paging to the end, which drives 30% of database read load.

If nothing changes, read load grows with customer data volume and the export use case keeps degrading. The expected outcome is constant-time page fetches and consistent results for clients.

2.1 Goals and non-goals

TypeStatement
GoalExample: p95 latency of any page under 200 ms regardless of depth
GoalExample: No duplicates or gaps while paging through a changing collection
Non-goalExample: Random access to page N
Non-goalExample: Changing the bulk export product (separate RFC)

3. Guide-level explanation

Example: Every list endpoint now returns a page object:

{
  "data": [{"id": "ord_123"}, {"id": "ord_124"}],
  "next_cursor": "eyJpZCI6Im9yZF8xMjQifQ",
  "has_more": true
}

To fetch the next page, pass the cursor: GET /v2/orders?limit=100&cursor=eyJpZCI6Im9yZF8xMjQifQ. Treat the cursor as opaque; do not parse or construct it. When has_more is false, you have reached the end. Sorting is fixed per endpoint (newest first for orders).

4. Detailed design

This section is the reference for implementers and reviewers.

4.1 Interface

The request and response types shared by all list endpoints:

interface PageRequest {
  limit?: number;      // 1..500, default 100
  cursor?: string;     // opaque, from previous response
}

interface Page<T> {
  data: T[];
  next_cursor: string | null;
  has_more: boolean;
}

4.2 Behaviour

  • Example: The cursor encodes the sort key and the ID of the last item (keyset pagination): WHERE (created_at, id) < ($1, $2) ORDER BY created_at DESC, id DESC LIMIT $3.
  • Example: Cursors are signed (HMAC) to prevent tampering and expire after 24 hours; an expired cursor returns 400 cursor_expired.
  • Example: A composite index on (tenant_id, created_at DESC, id DESC) is required for every paginated table.

4.3 Sequence

The sequence below shows a client paging through a collection.

4.4 Compatibility, security and operations

ConcernImpact
Backward compatibilityExample: offset accepted for 12 months with a Deprecation header
SecurityExample: Cursor signed and scoped to tenant; cannot be replayed across tenants
PerformanceExample: Constant-time queries; index adds ~3% write overhead
ObservabilityExample: Metric for offset usage per client to drive migration
DocumentationExample: API reference and migration guide updated

5. Drawbacks

  • Example: Clients cannot jump to page N; some admin UIs need redesign.
  • Example: Every client must migrate within 12 months; support load during migration.
  • Example: New index on three large tables; build takes about 2 hours each.

6. Alternatives

OptionProsConsDecision
Example: Keep offset, cap at 10,000No client changeBreaks exports; does not fix gapsRejected
Example: Expose raw keyset parameters (after_id)Simple, transparentLocks sort order into public API; tamperableRejected
Example: Opaque signed cursor (this proposal)Flexible, safeClient migrationChosen
Do nothingNo effortLoad and incidents growRejected

7. Prior art

  • Example: Our internal events API has used cursors since 20XX with no reported issues.
  • Example: Several large public APIs use opaque cursors with has_more flags; client libraries for them are common, which lowers the learning cost.
  • [Reference and lesson]

8. Unresolved questions

IDQuestionResolve byOwner
Q-1Example: Is 24 h cursor expiry enough for slow exports?Before acceptance@api-lead
Q-2Example: Do we offer a total_count field (expensive)?During implementation@product
Q-3[Question][Stage][@name]

9. Rollout

  1. Example: Phase 1: cursors on two endpoints behind a header opt-in; measure latency.
  2. Example: Phase 2: cursors default on all list endpoints; offset still accepted with Deprecation header.
  3. Example: Phase 3: contact the top 50 offset users; publish migration guide.
  4. Example: Phase 4 (month 12): offset returns 400; remove code path.

Success measures: [p95 page latency < 200 ms; offset share < 1% before phase 4]. Rollback: [disable the flag; offset path stays until phase 4].

10. Review log and decision

DateReviewer / forumFeedbackResolution
YYYY-MM-DDExample: @dbaIndex build must run onlineUse concurrent index build
YYYY-MM-DDExample: API guildCursor expiry too short for exportsRaised to 24 h (Q-1)
YYYY-MM-DD[Reviewer][Feedback][Resolution]

Decision: [Accepted / Rejected / Deferred] on YYYY-MM-DD by [decider]. Rationale: [One to three sentences, including conditions of acceptance.]

Section structure adapted from the Rust RFC template (rust-lang/rfcs, dual licensed MIT or Apache-2.0); text is original. Template licence: MIT.

Templat terkait