1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Domain layer configuration limits
//!
//! Defines validation constraints for domain-level pagination and query operations.
//! These limits enforce business rules and are independent of infrastructure.
//!
//! # Production Tuning
//!
//! These values are suitable for most deployments. Adjust based on:
//!
//! - **MAX_PAGINATION_LIMIT**: Increase if clients need larger batch fetches.
//! Monitor memory usage per request (limit * avg_item_size).
//!
//! - **MAX_PAGINATION_OFFSET**: Lower if cursor-based pagination is preferred.
//! Deep offsets are expensive; consider cursor pagination for offsets > 10,000.
//!
//! # Monitoring Recommendations
//!
//! Track these metrics to tune limits:
//! - `pagination.offset_p99`: If consistently high, clients may need cursor pagination
//! - `pagination.limit_avg`: Optimize batch sizes based on actual usage
//! - `query.scan_limit_reached_rate`: High rate indicates filter criteria too broad
/// Maximum allowed pagination limit per request.
///
/// Prevents single requests from retrieving excessive data.
/// Aligns with industry standards (GitHub API, Stripe use 100-1000).
pub const MAX_PAGINATION_LIMIT: usize = 1_000;
/// Maximum allowed pagination offset.
///
/// Prevents requests that would scan deep into result sets.
/// Beyond this, cursor-based pagination is recommended.
pub const MAX_PAGINATION_OFFSET: usize = 1_000_000;
/// Default maximum number of frames retained per stream by the in-memory
/// `FrameStore`.
///
/// Once a stream accumulates more than this many frames, the oldest are
/// evicted FIFO. Bounds the worst-case memory footprint of frame history
/// (10_000 frames × ~few-KB each ≈ tens of MB per very-long-lived stream).
pub const DEFAULT_FRAME_HISTORY_PER_STREAM: usize = 10_000;
/// Maximum number of frames a single `GenerateFramesCommand` may request.
///
/// Enforced by `CommandValidator::validate_generate_frames` at the
/// application boundary. Well under [`DEFAULT_FRAME_HISTORY_PER_STREAM`], so
/// a single request can never itself evict a stream's frame history.
pub const MAX_FRAMES_PER_REQUEST: usize = 1_000;
/// Maximum allowed `SessionConfig::session_timeout_seconds` (7 days).
///
/// Enforced by `CommandValidator::validate_create_session` at the
/// application boundary, before `StreamSession::new` computes
/// `now + chrono::Duration::seconds(session_timeout_seconds as i64)`. Any
/// `u64` value here fits well within `chrono::Duration::seconds`'s valid
/// range, so that addition can neither panic nor wrap into a negative
/// (already-expired) duration. The 7-day ceiling itself is an operational
/// choice, not a correctness requirement — sessions are not meant to be
/// long-lived resources.
pub const MAX_SESSION_TIMEOUT_SECONDS: u64 = 604_800;