1 Answer
- Newest
- Most votes
- Most comments
1
There are two ways I can think of doing this:
- Use a Global Secondary Index for each of the incoming (foreign) ids that you're going to use. That way you can efficiently (i.e. quickly from a code perspective) query the table using that id and it will directly pull out the item that you need. However, there is additional cost here because there is some extra storage required; and the indexes consume capacity independently of the main table. Note that there is a limit of 20 GSIs per table.
- For each "primary" item in the table that you retrieve using the internal id; create an extra item in the table which has the external id as the partition key and an attribute which contains the internal id. This will allow you to create as many external id to internal id mappings as you require. The downside here is that two queries are required to retrieve the primary item: You first take the supplied (external) id and query for that; then take the result and query for the "primary" item which holds the rest of the details. Additional cost because of storage and because of extra queries; lookups also take longer because of the additional query.
There are probably other ways of doing this but those were the first that popped to mind.
Relevant content
- asked 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 3 months ago
I fear 1. has the issues surrounding eventual consistency, the rate of change is expected to be relatively high and not under my control so this feels like it would work "most of the time" but be error prone.
I've actually gone for a 3rd option which is composing a system ID that is deterministic off the incoming external id plus some extra composite keys that uniquely identify it, it makes for an ugly PK but it is very efficient achieving single query read/writes, thanks.
Yup - that is a great idea; my assumption from the question was that it wasn't possible to do that given that the external id was not under your control; and somehow I got the idea there were multiple external parties so was overdesigning...