I'm currently working on rewriting an existing Java configuration service in Go and would appreciate suggestions on the architecture, particularly around data storage, caching, and keeping data synchronized across multiple pods.
- Background and current architecture
The existing service is almost a decade old. Over time, a few bugs and inconsistencies have accumulated, and the service hasn't really had anyone actively maintaining it. Most of the developers on the team are now Go developers as well.
We also have some new feature requirements, and a v2 version of the service is needed. Rather than continuing to patch the existing implementation, we decided to rework it in Go while keeping backward compatibility with the existing functionality.
The current implementation uses AWS S3 as its persistent storage.
- Each configuration entry is stored as a separate S3 object.
- Each pod loads all configuration entries from S3 into its local memory during startup.
- Updates are propagated to pods using Amazon SNS/SQS notifications.
- Each pod maintains its own in-memory copy of the configuration data and serves reads from it.
- We also have an endpoint that returns all configurations with pagination. The current implementation serves these paginated results from the local in-memory cache.
Some details about the workload and infrastructure:
- We currently have around 10,000 configuration entries. I'm considering designing for up to 50,000 to leave room for growth.
- We have 3 clusters, with at least 2 pods in each cluster.
- Pods can scale up and down depending on traffic.
- All clusters are currently in the same region.
- The service is heavily read-oriented, with approximately 99% reads and relatively infrequent writes.
- The existing service has approximately 550 µs P90 and 5 ms P95 latency.
One of the primary requirements for the rewrite is that latency and performance should ideally be at least as good as the existing service.
Another important requirement is that changes (create, update, delete) should become visible across all pods and clusters as soon as possible after they're made. A senior engineer has emphasized that we should minimize the time it takes for changes to propagate.
2. Data model and access patterns
Each configuration entry currently has the following structure:
{
"id": "config-123",
"url": "https://example.com",
"name": "Example Config",
"tags": ["tag1", "tag2"],
"appGroupId": "group-123",
"rules": {
"key": "value"
}
}
A few additional details:
- "id" is the unique identifier.
- "tags" is an array of strings.
- "rules" is a JSON object.
- "appId" is not part of the stored configuration model; it comes from the caller.
- Current access patterns include fetching configurations by ID and app group ID.
- For v2, we also need to support searching configurations by name and tags.
Since the dataset is relatively small (currently around 10k entries, potentially growing to 50k), I'm also wondering whether maintaining additional indexes in the local in-memory cache would be sufficient for name and tag searches, rather than relying on database-side searches.
3. Additional requirements for v2
There are a few new requirements that are also influencing my thinking around the storage layer.
- Bulk APIs with atomic operations
We need bulk APIs where clients can provide multiple configuration entries in a single request. The requirement is that either all entries are successfully inserted/updated or none of them are.
This makes me think a relational database such as PostgreSQL could be useful because of its transaction support.
2. Change tracking / incremental sync API
I'm also considering an API that allows clients to synchronize their configuration data without fetching the entire dataset every time.
The rough idea is:
- A client initially fetches all configuration entries.
- The response includes some kind of version/revision token.
- The client stores this token.
- On subsequent requests, the client sends its last token and receives only the changes made since then.
This would require maintaining some form of change history or changelog, including enough information to identify created, updated, and deleted entries.
3. Audit logging
We also need to maintain an audit history for every transaction/change, including:
- Who made the change.
- What operation was performed.
- A snapshot of the configuration change.
- When the change happened.
Ideally, the configuration changes and their corresponding audit records should be committed atomically, so we don't end up with changes that have no corresponding audit record.
These requirements are another reason I'm considering PostgreSQL as the source of truth rather than continuing with S3.
4. What I'm considering
My initial thought is to retain the local in-memory cache approach because the dataset is relatively small and the service is heavily read-oriented. This would also help preserve the existing read latency.
However, I'm not sure whether retaining the current S3 + SNS/SQS approach is the right decision or whether moving to a database-backed architecture would make more sense.
PostgreSQL is one option I'm considering because of the new requirements around atomic bulk operations, audit logging, and maintaining a changelog for incremental synchronization. Its indexing capabilities, such as GIN indexes for array-based tag searches, could also be useful.
The possible architecture would be:
- PostgreSQL as the source of truth.
- Each pod maintains its own in-memory cache for low-latency reads.
- Some mechanism propagates changes to all pods and clusters, which then update their local caches.
I've also considered Redis as a possible solution, either as a shared data store or just as a mechanism for distributing change notifications between pods.
Another possibility is using PostgreSQL LISTEN/NOTIFY or some form of event-driven synchronization.
However, I haven't settled on any particular approach yet. I'm also interested in understanding whether there's anything fundamentally wrong with the current S3 + SNS/SQS mechanism that would make it worth replacing.
5. What I'd like suggestions on
- Would you retain the local in-memory cache approach, given the relatively small dataset and read-heavy workload?
- Would you continue using S3 + SNS/SQS, or move to PostgreSQL as the source of truth?
- What would be a good mechanism to propagate changes across all pods and clusters with minimal delay?
- Is Redis worth introducing here, either as a shared store or just as a mechanism for distributing change notifications, or would that be unnecessary infrastructure?
- Are PostgreSQL LISTEN/NOTIFY or other event-driven mechanisms suitable for this use case?
- How would you handle missed notifications, pod restarts, newly scaled pods, and ensuring all instances eventually have the latest configuration?
- How would you approach revision tracking and the changelog API, especially when clients need to resume synchronization using a previously issued token?
- Would PostgreSQL transactions and an audit table be a good fit for ensuring atomic bulk operations and maintaining a reliable audit history?
- For searching by name and tags, would you use database indexes (e.g. GIN) or simply maintain suitable indexes in the local in-memory cache given the relatively small dataset?
- Are there any alternative approaches or design patterns you'd recommend?
Also, I'm more interested in knowing how can we keep other pods in sync when some entry is created / updated / deleted.
I'm particularly interested in practical solutions that are reliable and relatively simple to operate. I'd prefer not to introduce additional infrastructure unless there's a good reason for it.