Reddit Backend Project Using Microservice Architecture

Raghav  ShuklaRaghav Shukla
3 min read

What are Microservices

Microservices represent a software architecture approach where a complex application is built as a collection of small, independent services, each running in its process and communicating with others through well-defined APIs. The key principle is to decouple various functionalities into modular services, promoting flexibility, scalability, and ease of maintenance. Each microservice is responsible for a specific business capability and can be developed, deployed, and scaled independently.

Advantages

  • Enhanced modularity: Microservices break down applications into smaller, independent services.

  • Scalability: Each microservice can be scaled independently to meet specific demands.

  • Parallel development: Developers can work on individual components without affecting the entire system.

  • Flexibility: Easy integration of new features and updates without disrupting the entire application.

  • Resource optimization: Efficient utilization of resources by scaling specific microservices as needed.

Overview

Project Architecture

The project consists of 6 microservices. Each service is independent and loosely coupled so it doesn't affect other services.

Java version: 17, Dependency Management: Maven, Springboot Version: 3.2+

Spring Cloud Config

Spring Cloud Config is a tool in the Spring Cloud ecosystem that centralizes and manages application configuration settings. Instead of hardcoding configurations in every service we can fetch all the configurations from a central repository which eases the management and updating of config.
It also helps in having different configurations for different environments by creating multiple YML files for each environment. It also facilitates dynamic updates without the need for service redeployment.

I have used the following dependency to utilize the Spring Cloud config

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
</dependency>

Snapshot of Config File

Discovery Service

Using Eureka Discovery service here. helps microservices find and communicate with each other in a distributed system.each service registers itself with Eureka, and other services can look up its location when they need to interact with it.

Automatically locate and connect to services without hardcoding their locations, making the system more flexible and scalable.

LB:Distribute incoming requests among multiple instances of a service to improve performance and reliability.

API Gateway Service

An API gateway acts as a central hub for managing and securing interactions between clients and backend services. It streamlines tasks like authentication, authorization, and routing, enhancing security, performance, and scalability. By providing a unified entry point, it simplifies client access and enables monitoring and analytics for better insights and decision-making. In summary, API gateways play a vital role in modern architecture by optimizing communication and abstracting complexities.

User Service

Manages user-related operations such as user creation, retrieval, update, deletion, status change, searching, filtering, and association with subreddits, posts, and comments.

Subreddit Service

Manages subreddits, offering functionalities for creating, retrieving, updating, and deleting subreddits. Additionally, it handles user membership management within subreddits, association of posts, and interaction with comments.

Post Service

Comprising controllers for comments, posts, and votes, this service manages the core functionalities of the Reddit clone project. It facilitates the creation, retrieval, updating, and deletion of comments and posts, as well as the handling of voting interactions, ensuring a robust and engaging user experience.

Check out my project on GitHub

12
Subscribe to my newsletter

Read articles from Raghav Shukla directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Raghav  Shukla
Raghav Shukla

Passionate software developer crafting elegant solutions through code and innovation.