Skip to content

manthan55/SpringRedisSample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringRedisSample

This is a sample application demonstration redis caching capabilities in Spring Boot. This app is also deployable to AWS ElasticBeanstalk and integrates with AWS ElastiCache.


Reach out to Me


Application Overview

  • A simple post management system allowing Read operations on and Posts using SQLite DB as persistence store.
  • During the startup sequence, the project seeds dummy data into the SQLite database to have something to play with. This is done via the SeedData class within startup package.

Note: All data is wiped (from both SQLite DB as well as ES) on every reboot of the app.

  • The app has 3 endpoints
    • GET / -> Hello world endpoint which redirects to /actuator/info
    • GET /posts/ -> Get all posts
    • GET /post/{postId} -> retrieve post by id
      • The initial call will take 4 seconds to respond - but subsequent calls will be much faster thanks to reading from redis cache. The TTL for entries in cache is set to 30 seconds.

Note: As we are using SQLite database, the code intentionally includes a 4 second delay to simulate a proper (over network) DB call.

  • Refer postman folder for collection & environment (you can import in postman)

Spring Profiles

The Spring Boot project contain multiple application.yaml files accounting for multiple environments/profiles

  • application-local.yaml
    • is used when running the project locally via IntelliJ and uses the dependencies running in docker containers (or you can also setup other locally running dependencies)
  • application-aws.yaml
    • is used when the app is deployed on AWS Elasticbeanstalk and uses AWS Elasticache

The above profiles can be switched at runtime by setting the environment variable,

SPRING_PROFILES_ACTIVE=aws

Running Locally

  • Open the project in IntelliJ
  • Make sure the redis server is running before you run the project
    • redis server can be setup via docker or by any other means (docker setup can be achieved by running the provided docker-compose.yml file in the docker folder)

Running on AWS

  • Setup AWS ElastiCache (steps mentioned below)
  • Copy the AWS ElastiCache endpoint & port in application-aws.yaml file
  • Create a .jar file
  • Setup AWS ElasticBeanstalk and deploy the .jar file.

AWS ElastiCache Setup

  1. Go To AWS Elasticache > Redis OSS Cache > Create and then select the following configuration options Create AWS ElastiCache - Configuration

  2. Disable Cluster Mode - as this is just for demo we dont need multiple shards Create AWS ElastiCache - Cluster Mode

  3. Set cache name (and optional description) Create AWS ElastiCache - Cluster Info

  4. Set Location and make sure to disable MultiAZ and Auto Failover to save some bucks Create AWS ElastiCache - Location

  5. Cluster Settings

    • Parameter groups -> default.redis7
    • Make sure to select smallest node type -> cache.t2.micro
    • And set number of replicas to 0 Create AWS ElastiCache - Cluster Settings
  6. Subnet group settings

    • Provide a name and select a VPC
    • this will determine the placement of redis cache in the subnets and therefore its reachability from other subnets
    • it is preferred to select only private subnets
    • but as this is just for demo, I've selected all subnets available in the VPC Create AWS ElastiCache - Subnet Group Settings
  7. Availbility Zone Placements -- NO CHANGE Create AWS ElastiCache - Availbility Zone Placements

  8. Security

    • Disable Encryption at rest
    • Disable Encryption in transit
    • Select default security group of the VPC Create AWS ElastiCache - Security
  9. Backup

    • Disable as this is just for demo/learning purposes Create AWS ElastiCache - Backup
  10. Maintenance

    • Disable Auto upgrade minor versions Create AWS ElastiCache - Maintenance
  11. Logs

    • Disable Slow logs
    • Disable Engine logs Create AWS ElastiCache - Logs
  12. Hit Create

    • it takes about ~10 minutes to become available
  13. Once created the endpoint is available here Create AWS ElastiCache - Endpoint

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages