> For the complete documentation index, see [llms.txt](https://brightercommand.gitbook.io/paramore-brighter-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brightercommand.gitbook.io/paramore-brighter-documentation/outbox-and-inbox/brighterinboxsupport/inmemoryinbox.md).

# InMemory Inbox

The in-process Inbox: when to use it, how to configure it, and its limits.

> **Reference** · Applies to **Brighter V10** · Prerequisites: [InMemory Options for Development and Testing](/paramore-brighter-documentation/brighter-configuration/inmemoryoptions.md)

The in-process Inbox: when to use it, how to configure it, and its limits. It is part of Brighter's [InMemory options for development and testing](/paramore-brighter-documentation/brighter-configuration/inmemoryoptions.md).

The InMemory Inbox provides message deduplication without requiring a database.

## When to Use the InMemory Inbox

**Perfect for**:

* Unit testing duplicate message handling
* Development without database dependencies

**Production Use Cases** (limited):

* Single-process applications
* Short-lived message deduplication windows
* Non-critical deduplication scenarios

## InMemory Inbox Configuration

```csharp
using System;
using Microsoft.Extensions.DependencyInjection;
using Paramore.Brighter;
using Paramore.Brighter.Extensions.DependencyInjection;
using Paramore.Brighter.Inbox;
using Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection;

var bus = new InternalBus();

services.AddConsumers(options =>
{
    options.HandlerLifetime = ServiceLifetime.Scoped;
    options.InboxConfiguration = new InboxConfiguration(
        new InMemoryInbox(TimeProvider.System),
        actionOnExists: OnceOnlyAction.Warn
    );
    options.Subscriptions = subscriptions;
    options.DefaultChannelFactory = new InMemoryChannelFactory(bus, TimeProvider.System);
})
.AutoFromAssemblies();
```

Before Brighter 10.8.0 this configuration took effect only in an application that also called `AddProducers`; see [Global Inbox Configuration in a Consumer-Only Application](/paramore-brighter-documentation/outbox-and-inbox/brighterinboxsupport.md#global-inbox-configuration-in-a-consumer-only-application).

## InMemory Inbox Example Usage

```csharp
using System.Threading;
using System.Threading.Tasks;
using Paramore.Brighter;
using Paramore.Brighter.Inbox;
using Paramore.Brighter.Inbox.Attributes;

public class PersonCreatedHandler : RequestHandlerAsync<PersonCreated>
{
    private readonly PersonRepository _repository;

    [UseInboxAsync(0, typeof(PersonCreatedHandler), true, onceOnlyAction: OnceOnlyAction.Warn)]
    public override async Task<PersonCreated> HandleAsync(
        PersonCreated @event,
        CancellationToken cancellationToken = default)
    {
        // Inbox ensures this handler processes each message only once
        var person = await _repository.GetByIdAsync(@event.PersonId);
        person.MarkAsCreated();
        await _repository.SaveAsync(person);

        return await base.HandleAsync(@event, cancellationToken);
    }
}
```

The attribute decides what happens to a duplicate for this handler, whatever the configuration says. `onceOnlyAction` defaults to `Throw`, so without it a duplicate raises `OnceOnlyException` even though the configuration above asks for `Warn`. The configuration's `actionOnExists` applies only to handlers that carry no `[UseInboxAsync]` attribute of their own.

## InMemory Inbox Limitations

* **No persistence**: Deduplication state lost on restart
* **Single process**: Cannot deduplicate across instances
* **Memory bound**: Seen message IDs are held in memory. When adding an entry finds `EntryLimit` entries or more (2048 by default), the oldest are removed down to `CompactionPercentage` of the limit (half, by default), at most once per `ExpirationScanInterval`
* **A short deduplication window**: An entry expires `EntryTimeToLive` after it is written (5 minutes by default), and a scan removes it at most once per `ExpirationScanInterval` (10 minutes by default), started when an entry is added or read. A duplicate that arrives after its entry has gone is handled again

## Further Reading

* [InMemory Options for Development and Testing](/paramore-brighter-documentation/brighter-configuration/inmemoryoptions.md) - The full set, and testing patterns


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://brightercommand.gitbook.io/paramore-brighter-documentation/outbox-and-inbox/brighterinboxsupport/inmemoryinbox.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
