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.

질문됨 한 달 전542회 조회
1개 답변
1
수락된 답변

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
전문가
답변함 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠