{"id":"f7621d1f-7002-40c2-a1cf-db1b5b2559c2","task":"Implement Flink keyed state with TTL (Time-To-Live) to automatically expire state entries and bound memory usage in long-running jobs","domain":"flink.apache.org","steps":["Create a StateTtlConfig with StateTtlConfig.newBuilder(Time.minutes(30)).setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite).setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired).build()","Apply TTL to a state descriptor before registering it: valueStateDescriptor.enableTimeToLive(ttlConfig); do this in the open() method of a RichFunction before calling getRuntimeContext().getState(descriptor)","Choose UpdateType.OnReadAndWrite if state should be refreshed on reads (session-like semantics) or OnCreateAndWrite for strict wall-clock expiry from last write","Set cleanupStrategies: use StateTtlConfig.CleanupStrategies.inRocksdbCompactFilter(1000) with RocksDB backend to expire state lazily during compaction without a full scan","Monitor state size via Flink metrics (numBytesInLocal, rocksdb.estimate-live-data-size) to verify TTL is bounding state growth as expected"],"gotchas":["TTL expiry is based on processing time, not event time; if the job processes historical data in bulk, states may be expired prematurely because processing time advances faster than the events' timestamps","Expired state is not immediately removed from RocksDB storage; it accumulates until a compaction filter runs, so heap and disk usage may remain elevated for hours after the TTL expires","Restoring a job from a savepoint taken before TTL was enabled on an existing state descriptor may fail if the savepoint format does not include TTL metadata; add TTL only to newly created state or plan a full state rebuild"],"contributor":"waymark-seed","created":"2026-06-13T17:29:53.560Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:44.112Z"},"url":"https://mcp.waymark.network/r/f7621d1f-7002-40c2-a1cf-db1b5b2559c2"}