Skip to content

Commit c868f93

Browse files
committed
Add an ADR to keep document history in sync
1 parent 5a8efc2 commit c868f93

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# 5. Keep Document history in sync with RabbitMQ
2+
3+
Date: 2025-11-27
4+
5+
## Status
6+
7+
Accepted
8+
9+
## Context
10+
11+
When Content Blocks created in the Content Block Manager are used in documents, we want to be able to
12+
record when a change to a content block triggers an update to the host document. Currently this works
13+
like so:
14+
15+
* Content block is updated
16+
* We find all documents that use the content block
17+
* Each document is then represented to the content store with the updated content block details
18+
19+
This all happens in Publishing API, so there is no record in Whitehall (or any other publishing apps)
20+
of when a change to a document has been triggered by an update to a content block.
21+
22+
In order to do this, we need to update the Publishing API to record an event when a document has been
23+
republished as a result to a change to a content block. We can then have an endpoint that allows us to
24+
see the events for a particular document.
25+
26+
However, we still need a way to include these events in the history. Whitehall is particularly complex as
27+
the document history is stored in the database and [paginated][1]. This means we can't fetch the events and
28+
weave them into the history, as we don't have the entire history to hand to ensure we add the events to the
29+
right place within the history.
30+
31+
We could send a request to the Publishing API endpoint before we fetch the history and then create
32+
new events, however:
33+
34+
1. This will result in an API call every time a user views a document; and
35+
2. Carrying out an INSERT query on a GET request isn't a pattern we want to encourage
36+
37+
## Decision
38+
39+
With this in mind, we are proposing adding a new message queue consumer in Whitehall. Rabbit MQ messages
40+
are already sent by Publishing API when documents are republished, so we can consume the existing
41+
`published_documents` topic. We will set up a queue in Whitehall to listen for events with the
42+
`host_content` key, so we only listen for events triggered by a content object update. We did consider
43+
setting up a brand new topic for when `host_content` items were updated, but the `published_documents`
44+
topic has all the information we need and adding a new topic would come with added complexity and
45+
make the whole architecture more complicated.
46+
47+
When we receive a message, we will:
48+
49+
* Make a call to the `events` endpoint in Publishing API for that Content ID to find the latest
50+
`HostContentUpdateJob` event
51+
* Create a new `EditorialRemark` for the latest live edition for the Whitehall Document with that
52+
Content ID, informing the user that the document was republished by a change to the content block
53+
54+
Included in the events payload will be information about the triggering content block. We did consider
55+
sending this information as part of the payload, but concluded that we should make the effort to make
56+
the payload as small as possible, minimising bandwidth and reducing complexity in the Publishing API
57+
code.
58+
59+
## Consequences
60+
61+
We will need to set up a RabbitMQ consumer in Whitehall, which will require some minor work on the
62+
ops side of things. It will also mean we will need to consider two-way communication between the
63+
two applications when thinking about the publishing platform architecture.
64+
65+
However, once this is set up, this could potentially open up the possibility of more two way
66+
communication between Whitehall and Publishing API in the future, such as feeding back to
67+
the user when something has not published successfully.
68+
69+
[1]: https://github.com/alphagov/whitehall/blob/main/app/models/document/paginated_timeline.rb

0 commit comments

Comments
 (0)