MicroServices - Concurrency
Introduction
The Concurrency microservice backs the Concurrency Viewer — the small avatar pill that tells an operator which other users are currently viewing or editing the same record. It is a visibility feature, not a lock: concurrent saves are still arbitrated by the Data API's ETag-based optimistic concurrency. The service stores presence data in memory only and serves it over a small authenticated HTTP API.
Grounded against
origin/releases/7.0(MibMicroServices/Concurrency/…); the cited files are byte-for-byte identical onreleases/6.0.
Related docs. Concurrency Viewer — the React-shell/BFF side (polling, the
ConcurrencyWorkflowtracking, failure mode). System Overview — Concurrency MS — role, storage model.
Prerequisites
- Docker
- MibConfig via ENVVAR
- A reachable MibAuthorization service (to authenticate callers and resolve user ids)
No database — all state is in process memory (see How it works).
How it works
The service keeps a single in-memory, reference-counted map
(Repository/StructuredInMemory.cs), keyed by (mibIndex, component, mediaTypeId) → per-user
detail:
(mibIndex, ComponentsEnum, mediaTypeId) -> { userId -> UserDetail { LastRefresh, OperationEnum, References } }
userIdis taken from the caller's JWTsubclaim (ConcurrencyController.cs:103) — the microservice tracks the authenticated user, not the browser tab. (The per-tabuuiddedup lives one layer up, in the BFF'sConcurrencyWorkflow; see the Concurrency Viewer doc.)Referencesis a counter:LinkUserincrements it,UnlinkUserdecrements it (StructuredInMemory.cs:114,54). So the same user linked to the same item from several tabs/sessions counts asReferences = N, and only drops out when every one of them unlinks (or the entry expires).OperationEnum(Viewing = 0,Editing = 1) can migrateViewing → Editing, but reverts toViewingonly whenReferences == 1(StructuredInMemory.cs:103,123) — i.e. while any session still has it open for editing, the item shows as Editing to everyone.componentisComponentsEnum—MainComponent = 1(the whole item) orContentCriteria = 2(Model/ComponentsEnum.cs). A record and its content-criteria editor are tracked as independent presence buckets, so two operators working on different parts of the same item don't falsely appear to collide.
Expiration (sliding TTL). An entry is considered expired when References == 0 or
now - LastRefresh > SlidingExpirationTime (StructuredInMemory.cs:216). Eviction is a lazy
background sweep (ScanForExpiredItems): it runs at most once per InMemoryExpirationScanFrequency
and is triggered by any incoming request (StructuredInMemory.cs:132) — so if all traffic stops,
nothing is swept until the next request arrives. Because everything is in a ConcurrentDictionary, all
presence state is lost on pod restart (and rebuilt within a poll cycle) and is not shared across
replicas.
API Routes
Base route concurrency/v1; every route except the health check requires a Bearer token
([Authorize], ConcurrencyController.cs). mediaTypeIds is a CSV of content ids on the route
(GET/DELETE) or an int[] body (POST/PUT).
| Route | Verb | Auth | Purpose |
|---|---|---|---|
/concurrency/v1 |
GET | anonymous | Liveness — returns it's on!. |
/concurrency/v1/{mibIndex}/{component}/{mediaTypeIds} |
GET | Bearer | List other users on each requested id. Returns UserStatus[] per id (IEnumerable<IEnumerable<UserStatus>>), parallel to the input order. UserStatus = { Id, Status }. |
/concurrency/v1/{mibIndex}/{component}?type={0=Viewing\|1=Editing} |
POST | Bearer | Link — register the current user on the given ids. 201 Created. |
/concurrency/v1/{mibIndex}/{component}?type={0\|1} |
PUT | Bearer | Refresh — heartbeat the current user's link (resets the sliding TTL). 200 OK. |
/concurrency/v1/{mibIndex}/{component}/{mediaTypeIds} |
DELETE | Bearer | Unlink — decrement the current user's reference on the given ids. 200 OK. |
Swagger/OpenAPI is generated via AddSwaggerGen (vanilla Swagger UI, not the FileManagement MS's custom /help).
Configuration
Configuration is delivered as MibConfig sections (.mibconfig files or equivalent SECTION_KEY env
vars). Split by the service that needs it:
Required at Cms.MicroService (the Concurrency service itself):
MibConcurrencyConfig—Config/MibConcurrencyConfig.csKey Default Purpose slidingExpirationTime00:04:00How long an entry survives after the last refresh. Keep it above the BFF's userConcurrencyPollingTimeso steady polling never lets a live entry expire.inMemoryExpirationScanFrequency00:10:00Minimum interval between eviction sweeps. Lower it under high churn. userIdCacheExpirationTime00:01:00How long the service caches the user-id → user-info lookup it performs against MibAuthorization. MibAuthorizationClientConfig— theserverurlof the MibAuthorization service, used to authenticate callers and resolve user ids/info for the response.MibCacheConfig—app = true(enables in-process caching).
Required at Cms.FrontEnd (MibServer3 / the BFF):
MibCmsFrontEndServerBaseConfig—userConcurrencyServiceUrl(the MS URL) anduserConcurrencyPollingTime(default00:00:10). IfuserConcurrencyServiceUrlis unset, the shell skips the pill entirely. See the BFF-side reference.
(Concurrency is a FrontEnd-only feature — Cms.Api needs no concurrency configuration.)
Docker image & sample compose
The service is distributed only as a Docker image from Amazon ECR:
873339144623.dkr.ecr.us-east-1.amazonaws.com/agile/mib-cms-microservices-concurrency
873339144623.dkr.ecr.us-east-1.amazonaws.com/agile/mib-cms-microservices-concurrency-alpine
version: '3'
services:
mibconcurrency:
image: 873339144623.dkr.ecr.us-east-1.amazonaws.com/agile/mib-cms-microservices-concurrency-alpine
restart: unless-stopped
ports:
- 80:80
environment:
- mibauthorizationclientconfig_default_serverurl=http://cmsauth
- mibcacheconfig_default_app=true
- MibConcurrencyConfig_default_SlidingExpirationTime=00:05:00
Media-type resolution per component
Each concurrency link (/api/v2/concurrency/{pageKey}/link, refresh-link, viewers) is grouped by componentKey. The BFF resolves every component's media type before forwarding to the micro-service: it reads the component's MEDIATYPE template configuration and maps it to a MIB index. When a component has no MEDIATYPE configured, its links are skipped — the component is simply not tracked for concurrency.
EPG component fallback
The EPG component is configured through GRID_CONFIGURATION and does not necessarily declare a MEDIATYPE; the EPG grid itself falls back to the EPG_SCHEDULE media type in that case. Concurrency mirrors that fallback: for the EPG component, when MEDIATYPE is empty the link is resolved against the EPG_SCHEDULE media type instead of being dropped, so viewers and editors are tracked on the EPG page.
The fallback is fail-soft: if the EPG_SCHEDULE media type is not provisioned on the instance, the EPG link is skipped rather than failing the request. The fallback applies only to the EPG component — other components with an empty MEDIATYPE remain untracked, and a component configured with a media type that does not exist still surfaces the error (misconfiguration is not masked).
Integration with MibServer3 (the BFF)
The React shell never talks to the microservice directly — it polls the FrontEnd Server (BFF), which
proxies to the MS through IConcurrencyWorkflow/ConcurrencyWorkflow
(MediaiBox.Cms.FrontEnd.Workflow/MicroServices/Concurrency/ConcurrencyWorkflow.cs). On top of the
microservice's own model, the BFF adds:
- Per-tab
uuidtracking — one entry per browser tab/session (not per user), keyed by(mibIndex, ComponentsEnum). - A read-permission gate — before honoring Link/Refresh/Unlink it re-checks the caller's
CanReadon that media type (cached ~1 min) and returns401if revoked mid-session. - Proactive cleanup — a static in-process
(uuid → lastPing)map;CheckInactiveUsers()proactivelyDELETEs links that miss more than 5 poll cycles, in addition to the MS's own sliding-TTL eviction. This BFF-side state is per-process, so it does not survive a BFF restart or span BFF replicas.
The full BFF/React runtime flow, failure mode, and BFF-side configuration are documented in Concurrency Viewer.