Build Leaderboard with DynamoDB GSI

0

I'm going to create Leaderboard using this example as a reference. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html

There are two access patterns.

  1. Get Top 100
{
    "TableName": "GameScores",
    "IndexName": "GameTitleIndex",
    "KeyConditionExpression": "GameTitle = :v_title",
    "ExpressionAttributeValues": {
        ":v_title": {"S": "Meteor Blasters"}
    },
    "ProjectionExpression": "UserId, TopScore",
    "ScanIndexForward": false,
	"Limit": 100
}
  1. Get My Rank
{
    "TableName": "GameScores",
    "IndexName": "GameTitleIndex",
    "KeyConditionExpression": "GameTitle = :v_title and TopScore > :score",
    "ExpressionAttributeValues": {
        ":v_title": {"S": "Meteor Blasters"},
	":score": {"N": myScore},
    },
    "ScanIndexForward": false,
    "Select": COUNT	
}

Is this a good idea? I'm concerned that Getting My Rank will get slower as slower as getting more and more items like millions of items.

gefragt vor einem Monat542 Aufrufe
1 Antwort
1
Akzeptierte Antwort

DynamoDB would not be my go-to for a leaderboard, as other better alternatives exist. But i'm assuming here that you want to use a single database (DynamoDB) for your entire application....

While your first access pattern is highly efficient, your second one may not be as scalable. Imagine 1M players played the game Meteor Blasters and your rank is last place, you have to read 999,999 items to understand where you are in the list. That's going to be slow and expensive.

I would consider updating the users game rank on a daily basis for example, especially if they are not explicitly asking for it and its just used to populate a dashboard.

profile pictureAWS
EXPERTE
beantwortet vor einem Monat

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen