4. Observe catalog changes with Cratis Arc
Cratis Arc observable queries keep the catalog updated by sending new results to subscribed React components when the configured database observation source reports a change. Use the catalog from chapter 3 to verify that path in two browser tabs, then distinguish same-process updates from external writes.
Why the screen already moves
Section titled “Why the screen already moves”The queries in earlier chapters return streams: ISubject<…> on C#, Flow<List<…>> on the JVM, and ObservableSource<…> on TypeScript. Arc exposes those streams as observable queries. The generated React .use() hook subscribes to results instead of fetching a list just once:
When a command writes and the observation source reports the change, the query publishes updated data and React re-renders the catalog. The command does not tell the screen to refresh; the subscription connects the database notification to the next result.
Verify the scope of observation
Section titled “Verify the scope of observation”Keep the database and backend setup from chapter 3, then check the screen:
- Open two browser tabs connected to the same backend process and display the same author’s catalog in both.
- Add a book in one tab. Confirm that it appears in the other without reloading.
- Add another book from the second tab and confirm that the first tab updates too.
This checks the tutorial’s live path, including the C# SQLite setup. It does not establish that a write from another process will be observed. That depends on the database integration:
- MongoDB uses change streams on a replica set or supported sharded deployment, including the JVM and TypeScript integrations. A configured change stream can report external writes.
- C# observed
DbSetqueries receive same-process notifications through the configuredSaveChangesinterceptor. SQLite uses only that path. SQL Server and PostgreSQL need database notification setup for cross-process detection; if setup fails, EF observation can fall back to same-process notifications. Inspect server logs before testing external writes. - JVM JPA observation uses explicit in-process change publication after commit. See observable snapshots for the publisher and transaction behavior.
- TypeScript Drizzle observation requires table registration and explicit change announcements after committed writes. Follow observe SQL tables for that setup.
If the second tab stays stale, check the backend notification source as well as the browser connection. A subscription can remain connected without receiving fresh data.
What makes a query live
Section titled “What makes a query live”The following are alternative MongoDB method fragments in Author, using the tutorial imports. Replace the method rather than adding a second method with the same signature.
A one-shot query returns the current data and completes:
public static IEnumerable<Author> AllAuthors(IMongoCollection<Author> authors) => authors.Find(_ => true).ToList();public static List<Author> allAuthors(@FromServices AuthorRepository authors) { return authors.findAll();}@JvmStaticfun allAuthors(@FromServices authors: AuthorRepository): List<Author> = authors.findAll()@query(service(AuthorRepository))static allAuthors(authors: AuthorRepository): Promise<Author[]> { return authors.all();}The observable version returns a stream backed by database observation. Replace the method with this version, then regenerate the proxies using your backend’s chapter-1 command. The generated .use() hook subscribes to the stream; the catalog component keeps the same hook call:
public static ISubject<IEnumerable<Author>> AllAuthors(IMongoCollection<Author> authors) => authors.Observe();public static Flow.Publisher<List<Author>> allAuthors(@FromServices MongoObservableQuery queries) { return queries.observePublisher(Author.class);}@JvmStaticfun allAuthors(@FromServices queries: MongoObservableQuery): Flow<List<Author>> = queries.observe<Author>()@query({ observable: true }, service(AuthorRepository))static allAuthors(authors: AuthorRepository): ObservableSource<Author[]> { return authors.observeAll();}Choose per query. A lookup that only needs data when opened can return a plain list. Use an observable query when the screen should reflect later changes, and configure the notification source for the writes it needs to see.
What you built
Section titled “What you built”The two-tab check follows a write through database observation, the query subscription, and React rendering. Keep the same-process and external-write checks separate so a working local catalog does not hide a missing cross-process notification source.
Next, restrict catalog access →. You’ll require the Librarian role on commands and queries, then test access with and without that role.