amazon-qldb

Amazon QLDB Design Pricinples


I'm wondering the best way to design tables in QLDB and whether it's best to perform joins or perhaps have nested documents. For example, if I have the tables transaction and payment where a payment must be associated to a transaction. Which of the following options are best;

Nested Document Option (One table)

{
    'payment_reference': 'abc123',
    'transaction': {
        'id': 123,
        'name': 'John Doe',
        'amount': '$10'
    },
    'fees': '$2',
    'amount_paid': '$12'
}

Two Table Option

Payment Document

{
    'payment_reference': 'abc123',
    'transaction_id': 12,
    'fees': '$2',
    'amount_paid': '$12'
}

Transaction Document

{
    'id': 123,
    'amount': '$10',
    'name': 'John Doe',
   
}


Solution

  • I think @Aurgho has answered your question. But I am going to put my general thoughts based on what Aurgho said, which might help others coming to this post with similar question.

    There are multiple factors that can influence your design decision, along with the quotas and limits QLDB imposes. Here are few pointers that might help you think forward:

    Generally speaking, if you are not going to query on a field in the nested document and/or your writes >>> reads and/or your reads are not super sensitive to latency and/or your document size will stay within the currently imposed limits, you could do with Option #1. Having all your data in one document can ease you at the application layer when you are pushing the data into QLDB(just one insert) and when you have to process the documents in your code, but you will have to choose your trade-offs correctly.

    These are just general pointers to help you think forward. You could have other use cases where either of the design options becomes more convincing than the other and you can trade-off certain advantages/disadvantages between the two.

    Also, QLDB has some recommendations to optimize your query performance, which can further help you with your decision https://docs.aws.amazon.com/qldb/latest/developerguide/working.optimize.html