Say you’re writing a table to store stock symbol information.
Let’s say you have a record like this:
Let’s assume the PK is some symbolID we can use for our primary use case. Getting the data is easy, you just form a PK and run client.get. In some use cases though you would need ability to lookup by SymbolName or SymbolType. Depending on the cardinality and use case, you may choose a variety of different methods. The easiest is of course secondary index.
Another method to do this would be to write a reference record.
setSymbols may contain records like this: PK,SymbolName,SymbolType,Price. Lets assume we are looking at 1 record… with values “1234,GOOG,F,123”
Now if we need a way to look this record up from not just the PK (1234) but also the SymbolName (GOOG) we can write a reference set.
setSymbolReference: PK,SymbolID… continuing this example, we could have the values of the record we need to lookup goog as “GOOG, 1234”.
So step 1 is to lookup the reference key which points to the real primary key, step 2 is to get the actual data.
- get(GOOG) => 1234
- get(1234) => data!
The pitfall is that you need to update 2 records whenever 1 update comes through.