Burak Aktas Software Engineer

Spring Security with JWT Tutorial

In this tutorial we will learn how to implement secured APIs in Spring Boot with using JWT tokens. First of all, we have to understand what is a JSON Web Token (JWT).

JWT is an open standard (RFC7519) to share information between entities in a JSON format. It is digitally signed thus it can be verified by entities. It is not encrypted but encoded which means if the man in the middle gets the token then it can be used for accessing secured resources. Because of this it shouldn’t contain any critical information like password, credit card number etc. This can be prevented by encryption with TLS or you can basically choose to encrypt JWT as well which is optional.

Initial Guide to Deploying Docker Containers into AWS ECS

In this tutorial we will walk through how to deploy simple docker containers into AWS ECS. ECS is a container service to deploy and manage your Docker containers on AWS. Basically, there are two types to deploy containers on ECS clusters which are;

  • EC2 instances
  • Fargate (Serverless)

We will use EC2 type container instances. Before starting there are some components specific to ECS terminology which we need to understand;

  • Task Definition: JSON|YML based configuration file. In other words recipe or blueprint of your containers. We give parameters like Docker Image, CPU, Memory, Network Mode for one or more containers. You can think of it like a Dockerfile.
  • Task: An instance based on given Task Definition. This is the Docker container which can contain one or more Task Definitions.
  • Service: Allows you to create and maintain a number of tasks (containers) including their lifecycle and deployment properties from same Task Definition.
  • ECS Container Agent: A service (docker container) that manages the connection between ECS cluster.
  • Cluster: Group for defining container instances. It can be either group of EC2 instances or a Fargate type cluster which is serverless.

Spring Schedule Tutorial

In this tutorial we will walk through how to implement and define crob jobs with a schedule behind of it in Spring Framework. Generally, in software architectures we want to have some background jobs to do some processing, aggregating or even just fetching some data and streaming them. Instead of implementing separate cron jobs and managing them as a separate application we can create and maintain cron jobs in same spring application with using @Scheduled annotation. Generally, all the scheduled tasks will run on the same thread which means when current task is being processed others will get blocked and has to wait current thread to finish. However, this can be configured by implementing our own ThreadPoolTaskExecutor to assign a thread pool. So that each task will run asyncrohonously.

Build Serverless Disposable Email Address Architecture on AWS

In this tutorial I will walk through about building a disposable email address architecture on AWS for received emails. We will be able intercept emails and process their attributes like subject, body, attachments etc. Nowadays, there are so many online products requires a valid email to send a verification code to complete registration. In these cases you may not want to give your personal or work email which you can have a disposable email address for these kind of temporary operations.

  1. Intercept incoming emails and filter through defined rule set in AWS SES.
  2. Save email with its contents into S3.
  3. Invoke an AWS Lambda function to process received email by getting email contents from S3 with its messageId.

Spring Retry Tutorial

In this tutorial I will talk about some retry examples in Spring and how to do it. Retry logic or in other words retry strategies are being used when an operation is failed and we want to basically retry that operation again by a logic. Most of the software systems are doing external calls, operations etc. which are dependent on other systems or resources. For example, charging a client by sending a charge request to Stripe, sending a message to Amazon SQS queue which might failed for a short time due to a transitive issue. Instead of, failing the process at the very first try we can basically have a retry strategy to try the current operation multiple times to continue current process without any issue. In Spring, there are multiple ways to define how to retry on some operation.