r/learnprogramming • • 2h ago

Need help on DB2 design

Problem Statement

We have a transaction history table (CARDTXNHIST) used by a banking application to display customer transactions.

​The daily batch process consists of two stages:

​Unstatemented Transactions (Code = 2) batch file → TEMP table → View → CARDTXNHIST

​Existing Code=2 records are deleted and refreshed

​Statemented Transactions (Code = 3)

​Separate batch file → TEMP table → View → CARDTXNHIST

​Statemented records are loaded after unstatemented processing

​The batch window runs approximately between 4 AM and 9 AM.

​Observed Issue

On statement cycle dates, the incoming unstatemented dataset may be empty because all eligible transactions have been statemented.

​As a result:

​Code=2 transactions are removed/refreshed

​Code=3 transactions are still being processed

​During this period, customers may see no transaction history in the application, even though the transactions still exist within the batch pipeline.

​Objective

We are looking for database/application architecture approaches that can eliminate or minimize this visibility gap while the batch is in progress.

​Solutions Under Consideration

​Retaining Code=2 records until Code=3 processing completes

​Shadow table / table-swap approach

​Composite views

​Deferred commit strategy

​Reading from staging/view sources during batch processing

​Data archival and performance optimization

​Other database design recommendations

​Questions

​What would be the recommended design pattern to ensure customers always see a consistent transaction history?

​How have similar large-scale batch processing systems solved this "delete-before-republish" visibility gap?

​Are there DB2-specific approaches (isolation levels, shadow tables, transition tables, view-switching, etc.) that would be suitable for this scenario?

​If you'd like to adjust the length or add any extra context (like table volume or specific DB2 version) before posting, let me know!

1 Upvotes

3 comments sorted by

•

u/ookkroam 43m ago

I would not delete the Code=2 rows from the live table until the Code=3 load has finished, especially on statement dates when the unstatemented file is empty. A shadow table works well here: load both batches into a new copy of CARDTXNHIST, then switch a view or synonym over to it in one step so the app never reads a half-updated table. If a full swap is too much for the morning window, just deferring that delete until after the Code=3 commit already removes most of the gap.

•

u/forestking101 38m ago

Staging tables exist so live readers do not watch sausage getting made.

•

u/NW1969 32m ago

This feels like a process issue, not a technology issue:
- process code 3 transactions before code 2 transactions
- include code 2 transactions in the batch file when you know there is a corresponding code 3 transaction (and remove the code 2 when you process the code 3)
- probably lots of other process-based solutions