Developing a Game Leader Board using Spring Boot + Redis in AWS Cloud

The Game Leader Board Deployment Architecture

Step 1

@Service
public class GameLeaderBoardService {

@Autowired
private RedisTemplate<String, String> redisTemplate;

@Resource(name = "redisTemplate")
private ZSetOperations<String, String> zSetOperations;

public List<Gamer> add(Gamer gamer) {
zSetOperations.add("leaderboard", gamer.getName(), gamer.getRank());

return zSetOperations.rangeWithScores("leaderboard" ,0,10)
.stream().map(e -> new Gamer(e.getValue(), e.getScore()))
.collect(Collectors.toList());
}

public void deleteAll() {
zSetOperations.getOperations().delete("leaderboard");
}
}
@RestController
@RequestMapping("/gameleaderboard")
public class GameLeaderBoardController {

@Autowired
private GameLeaderBoardService gameLeaderBoardService;

@PostMapping
public List<Gamer> add(@RequestBody Gamer gamer) {
return gameLeaderBoardService.add(gamer);
}

@DeleteMapping
public void deleteAll() {
gameLeaderBoardService.deleteAll();
}

}

Step 2

Creating an ElastiCache Redis instance

Step 3

#!/bin/bash
yum update -y
sudo yum install -y java-1.8.0-openjdk
wget https://github.com/shazin/spring-boot-redis/releases/download/v0.0.3/spring-boot-redis-0.0.3.jar
sudo java -Dserver.port=80 -Dspring.redis.host=<ELASTIC_CACHE_REDIS_HOST> -jar spring-boot-redis-0.0.3.jar
Launching EC2 Instances

Step 4

Creating Target Group
Registering EC2 Instances in Target Group
Target Group Provisioning EC2 Instances as healthy

Step 5

Creating Application Load Blancer

Step 6

Initial POST Request to Add to Leaderboard
Subsequent POST Requests to Modify the Leaderboard

Conclusion

--

--

--

Coder, Maker, Father

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

IoT Cloud — An Overview of the Nucleus of an IoT Solution

IoT Cloud and Security

On the Corner of My Bed

Basics about JaCoCo Maven Plugin

Create a Custom UIButton in Swift

Version Of Java Should I Use As A Beginner

learn java with practice test

Day 10–11/5/20

Android 11 Developer Preview: Permission Changes

informatica bdm online training

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shazin Sadakath

Shazin Sadakath

Coder, Maker, Father

More from Medium

Tracing Java based Lambda using X-Ray and AWS PowerTools

Blue/Green Deployment of API Using AWS Lambda and API Gateway

Working with AWS Lambda | Part-1

How to configure API Key in AWS API Gateway.