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.

preguntada hace un mes550 visualizaciones
1 Respuesta
1
Respuesta aceptada

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
EXPERTO
respondido hace un mes

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas