How do we create a projection to write metadata to streams?

Hi there,

Background

  • A subset of our Event Store streams only need to store the last n events in them. We’ve been told we can write a projection that writes metadata to [some category name] streams to achieve this
  • I’m guessing this is a fairly standard requirement but we haven’t any experience with custom projections. :slight_smile:
  • We currently enable a single system projection and have no custom projections running.

Question

Could anyone point us towards what such a projection would look like please?

(we’re trying to alter the metadata for all streams in a particular category - and set the maxCount (or maxAge) for these streams)

Additional questions

  1. Am I correct in understanding that the maxCount metadata is actually applied to the stream (and events truncated) only when scavenging?
  2. Are there any operational concerns we should be considering when we enable this custom projection? (apart from monitoring the projection state via stats)
  3. I guess I could write the same metadata (in application code) when we initially create the stream - is this considered a better/safer approach to stay away from custom ES projections? (I’ve seen various issues/comments on this forum about custom projections causing issues).

Thanks,

Justin

the metadata steam is $${stream-name}

  1. Am I correct in understanding that the maxCount metadata is actually applied to the stream (and events truncated) only when scavenging?
    No. The steam will only ever show you $maxCount events on sttream reads. The events that “fall off” the end will eventually be scavenged.

  2. Are there any operational concerns we should be considering when we enable this custom projection? (apart from monitoring the projection state via stats)
    Depending on what your load is projections can cause write amplification

  3. I guess I could write the same metadata (in application code) when we initially create the stream - is this considered a better/safer approach to stay away from custom ES projections? (I’ve seen various issues/comments on this forum about custom projections causing issues).
    I would normally just do it in my application adding projections is another moving part that is adding little value in this case