r/java • • Oct 07 '26

Push-based, restart-free feature flags and config for Spring Boot, using MongoDB Change Streams

configstream is a library for Spring Boot services that already use MongoDB. Feature flags and config live in a collection, get cached in memory, and any change is pushed to every running instance within about a second via MongoDB Change Streams.

  • No restarts, no polling, no message broker, no config server
  • Properties declared in a configstream.yml manifest, with typed constants generated at compile time
  • Optional admin UI with change history and per-team permissions
  • Works with Spring Boot 3 and 4

Limits: MongoDB only for now (Postgres planned), pre-1.0, no percentage rollouts or A/B testing.

https://github.com/configstream/configstream

Feedback welcome.

0 Upvotes

5 comments sorted by

View all comments

3

u/[deleted] Oct 07 '26

[removed] — view removed comment

1

u/reachkhajam Nov 01 '26

Hi u/Nearby-Material-4276

Thanks, good questions.

Types: not just booleans. The manifest supports boolean, int, decimal and string, and each constant is generated with its type:

properties:
  - key: limits.max
    type: int
    initialValue: 100
    description: Maximum items per order

becomes Limits.MAX, a Property<Integer>, so int limit = config.get(Limits.MAX); compiles and returns an int. Decimals are BigDecimal, so thresholds like 0.75 don't pick up float rounding. Values are validated against their type when written from the admin UI. If someone puts a bad value straight into Mongo (say "abc" for an int), it's skipped with a warning and the app keeps using the manifest value until it's fixed.

Delta vs. full reload: it's the delta. The stream is opened with fullDocument: updateLookup, so each event carries the whole changed document (one doc per property, _id is the key). The cache just does put(key, value) or remove(key) for that one key. No collection read, no invalidate-then-refetch.

So with 200 instances and one flag flip, MongoDB sends 200 change events, and the update lookup is a fetch by _id for each stream. That's 200 point reads, not 200 collection scans.

A full find() happens only:

  • at startup (the stream is opened before the snapshot is read, so nothing written in between is lost)
  • if the resume token has fallen off the oplog, or the collection is dropped or renamed
  • if the watcher thread dies and restarts

A normal disconnect or primary failover resumes from the last resume token, with no reload. Reloads update the map in place, so readers never see it empty.

On the hidden cron job: fair suspicion, so to be exact: there's no scheduled re-read of the collection. The watcher thread does loop on the cursor's tryNext(), which is a server-side await (about 1s by default) on the oplog, the standard way the driver tails a change stream. A change shows up as soon as it's written, not on the next tick.

One honest caveat at your scale: each instance holds its own change stream, so 200 instances means 200 open streams on the replica set. That's fine for MongoDB in general, but worth knowing. Also, reconnect backoff is exponential (200 ms up to 30 s) but has no jitter yet, so after a primary outage all 200 would retry roughly together. I'll add jitter, thanks for the nudge.

The whole walkthrough, with every screenshot in order https://github.com/configstream/configstream/blob/main/docs/walkthrough.md