Backend Engineering

Xurshidbek Kurbanov
9 min readNov 19, 2024

--

A Cup of Java ☕

Java EE, Spring Framework

JDBC, JPA, Spring Data JPA

Web Application, Spring Boot

IT Project, Large-scale traffic

“Backend Engineering — More than a concept” by Xurshidbek

Java EE, Spring Framework

Lesson-1: SpringBoot Project

Task Management Project-I

Spring Boot, Spring Data JPA

Template Engine (Thymeleaf), PostgreSQL

Maven vs Gradle

dependency-management

spring-boot-autoconfigure

Lesson-2: Spring Framework, Bean

Enterprise Java Beans (EJB)

Expert One-on-One

JEE Design and Development

ApplicationContext.java

Beans.properties

Aspect Oriented Container

Default Constructor

Singleton & Prototype

Lesson-3: Application Context, XML

Interface ApplicationContext

Interface BeanFactory

ClassPathXmlApplicationContext

spring-core jar maven

spring-context jar maven

Spring Modules (Core Container)

applicationContext.xml

Inject with Spring configuration

Lesson-4: AnnotationConfigApplicationContext

XML inconvenient to use

Class AnnotationConfigApplicationContext

Annotation (Java Config, Component Scan)

@Configuation — application config

@Bean — method level

@Component — class level

Lesson-5: Java EE, WAS, Tomcat

Web Application, WAS

WAS — Web Application Server

Java EE Standard WAS

Java EE Platform Specification

Transition from Java EE to Jakarta EE

Java Web Programming

Servlet Container, JSP

WAS, Tomcat

Run Tomcat in the foreground

Run Tomcat in the background

Deploy the application on Tomcat

Lesson-6: HTTP Protocol, HttpServlet

DNS, nslookup

IP address, Port number

Chrome Developer Tools

Http Request, Response

Special Type of Servlet (JSP)

Http Servlet Request

Http Servlet Response

Spring Web Programming

Core class-Dispatcher Servlet

Lesson-7: Servlet & JSP Life Cycles

Servlet Life Cycles

init, destroy, service

service (GET, POST, PUT, DELETE)

JSP Life Cycles

jspInit, jspDestroy, jspService

Servlet Project

Request Dispatcher

Lesson-8: Servlet to JSP, EL Notation

Servlet Project

Forward from Servlet to JSP

JSP, EL Notation

Maven Lifecycle

Maven Install

Deploy WAR on Tomcat

Lesson-9: Java EE Project

Task Management Project-II

Jakarta EE, Servlets

JDBC, PostgreSQL

Connection, DriverManager

JavaServer Pages Tag Library (JSTL)

Lesson-10: Spring Framework

Jakarta EE to Spring Project

Compile Only Dependency

WAR, Deploying on Tomcat

Spring Core Container

Spring Web MVC

WebMvcConfigurer

WebApplicationInitializer

Browser(/hello) => Tomcat => Servlet (HelloServlet)

Browser(/hello) => Tomcat => Servlet (DispatcherServlet) =>ApplicationContext => Bean(Controller(“/hello”))

Lesson-11: Default Servlet, ViewResolver

Browser(/img.png) => Tomcat => Servlet (DispatcherServlet (/)) =>ApplicationContext => Bean(Controller(“/img.png”))

Browser(/img.png) => Tomcat => Servlet (DispatcherServlet (/)) =>ApplicationContext => Bean(Controller(“/…”)) => Tomcat DefaultServlet => webapp/img.png

Default Servlet Handler Configurer

Internal Resource View Resolver

Controller logic => InternalResourceViewResolver => Show using JSP

Controller logic => BeanNameViewResolver => Download using Excel

Lesson-12: DataSource, PropertySource

WebApplicationInitializer

AbstractAnnotationConfigDispatcherServletInitializer

getServletFilters, getRootConfigClasses

getServletConfigClasses, getServletMappings

Database Programming

SQL, JDBC, Spring JDBC, Spring Data JPA

Controller, Service, DAO, Repository

DriverManagerDataSource

AbstractDriverBasedDataSource

AbstractDataSource, DataSource

Lesson-13: Setting up Spring Data JPA

JDBC, Connection Pool

MyBatis, Spring JDBC, Spring Data JPA (ORM)

Transaction, EntityManager, PersistenceContext, JPAException

Transaction, Transactional

EntityManager, LocalContainerEntityManagerFactoryBean

DataSource, HibernateJpaVendorAdapter

JPAException, Spring Exception

Lesson-14: Spring Framework Project

Task Management Project-III

WebConfig, AppConfig

MyWebApplicationInitializer

Spring Data JPA, PostgreSQL

Controller, Service, Repository

Default Servlet, ViewResolver

DataSource, TransactionManager

EntityManager, EntityManagerFactory

JDBC, JPA, Spring Data JPA

Lesson-1: JDBC, PostgreSQL Driver

Java Database Connectivity (JDBC)

MySQL, PostgreSQL, Oracle Drivers

Maven Archetype Project

Connection, PreparedStatement

ResultSet, DriverManager

PostgreSQL JDBC Connector

Connect SQL, Insert SQL

Delete SQL, Select SQL

Lesson-2: SQL, JDBC Transactions

SQL Transactions

Auto Commit = False

(begin, commit)

(begin, rollback)

Transaction Lock (SQL)

JDBC Transactions

connection.setAutoCommit(false)

connection.commit()

connection.rollback()

Transaction Exception

Transaction Lock (JDBC)

Spring JDBC, MyBatis, Spring Data JPA

Lesson-3: JDBC, SpringBoot

Spring Boot (3.3.x) System Requirements

Maven 3.6+, Gradle 7.x and 8.x.

Tomcat 10.1, Servlet version 6.0

JDBC API, PostgreSQL Driver

Dependency AutoConfiguration

DataSourceAutoConfiguration

JdbcTemplateAutoConfiguration

DataSourceProperties

application.properties (application.yml)

main class not managed by Spring

DataSource, CommandLineRunner

Lesson-4: HikariCP, ConnectionPool

SpringBootApplication is Component

External Libraries, HikariDataSource

HikariDataSource in Spring Beans

SpringBoot Connection Pool

HirakiCP, Oracle UCP, Tomcat Pooling

DataSource, HikariDataSource

Unlimited Connections without closing

Unlimited Connections with closing

Slow-running SQL queries

Lesson-5: Spring JDBC, DAO

Spring JDBC, Data Access

JdbcTemplate, RowMapper

NamedParameterJdbcTemplate

Client, Controller, Service, DAO, DB

Spring JCBC, Add, Delete, Get

SimpleJdbcInsert

SqlParameterSource

MapSqlParameterSource

BeanPropertyRowMapper

Lesson-6: Hibernate with JPA

JPA Provider, Native Hibernate

Hibernate ORM (2001) => JPA (2006) => JPA 2.1 (2013)

DataNucleus, EclipseLink, Hibernate

Spring Data JDBC

Spring Data Redis

Spring Data JPA

Maven Archetype, persistence.xml

EntityManager, EntityManagerFactory

Persistence Context, CRUD

Lesson-7: Entity Mapping, Identifiers

Entity, Table, Id, Column, Enumerated

EntityManager, EntityManagerFactory

Id Annotation — Direct Assignment

Id Annotation — Identifier Column Method

Id Annotation — Sequence Usage Method

Id Annotation — Table Storage Method

GeneratedValue, GenerationType.IDENTITY

GeneratedValue, SequenceGenerator

GeneratedValue, TableGenerator

Lesson-8: Embeddable, Embedded

Not an Entity — Embeddable

Not an Entity — Embedded

EntityManager, EntityManagerFactory

AttributeOverrides, AttributeOverride

@SecondaryTable + TableName

@SecondaryTable+@AttributeOverride

Lesson-9: Mapping Set, List, Map

EntityManager, EntityManagerFactory

ElementCollection, CollectionTable-Set

Mapping Set, Embeddable

FetchType.EAGER, FetchType.LAZY

ElementCollection, CollectionTable-List

Mapping List, OrderColumn, Embeddable

ElementCollection, CollectionTable-Map

Mapping Map, MapKeyColumn, Embeddable

Lesson-10: Persistent Context, Lifecycle

JPA — EntityManager

JPA — Transaction

JPA — Persistence Context

Persistence Context, Repeatable Read

Lifecycle: Managed, Detached, Removed

Change Entity with close

Change Entity with detach

Lesson-11: 1–1, N-1, 1-N, N-N

Unidirectional Associations

One-To-One Relationship

Primary Key (PK), Foreign Key (FK), JoinColumn

Primary Key (PK), Primary Key (PK), PrimaryKeyJoinColumn

Many-To-One Relationship

One-To-Many Relationship (Set, List, Map)

Many-To-Many Relationship

CascadeTypes, CascadeType.PERSIST

Bidirectional Associations

One-To-Many with mappedBy

Many-To-Many with mappedBy

Lesson-12: JPQL, CRITERIA

EntityManager, EntityManagerFactory

Jakarta Persistence Query Language

TypedQuery, CreateQuery

select r from Review r where r.hotelId = :hotelId

JPA Criteria Queries

CriteriaBuilder, CriteriaQuery

Root, Predicate, TypedQuery

Lesson-13: Spring Data JPA, Entity Manager

DataSource (HirakiCP)

DataSourceProperties

EntityManagerFactory (Hibernate)

EntityManager

EntityTransaction

Entity, PersistenceContext

Transaction Begin, Commit

Transaction Begin, Rollback

EntityManager Persist

Lesson-14: Spring Data JPA, Query Methods

findByName, findByNameAndEmail

findByNameNot, findByNameOrEmail

findByUserIdBetween, existsByEmail

findByUserIdLessThan, findByUserIdGreaterThan

findByRegdateAfter, findByRegdateBefore

findByNameIsNull, findByNameIsNotNull

findByNameLike, findByNameContaining

findByNameStartingWith, findByNameEndingWith

findByOrderByNameAsc, findByOrderByNameDesc

findByUserIdIn, findByUserIdNotIn

findByFlagTrue, findByFlag(flag)

countBy, countByNameLike

deleteByName, deleteByNameLike

findFirst2By, findTop2By

findByName(String name, Pageable pageable)

Lesson-15: Spring Data JPA, Associations

User Entity, Role Entity, Task Entity

ManyToMany, JoinTable, JoinColumn

Do not use ToString

ManyToOne, JoinColumn

N+1 Problem in Hibernate

findAll, EAGER, LAZY, Join Table

findById, EAGER, LAZY, Join Table

JPQL, Join, Join Fetch

Native Query, Projection

Web Application, Spring Boot

Lesson-1: Customized Tomcat

Web Application Server (WAS)

Create Tomcat using Java

Web Socket with Port

Requests in Main Thread

Requests in New Thread

Requests using Thread Pool

Lesson-2: Embedded Tomcat

Web Application Server (WAS)

Tomcat Embedded Core

Tomcat Embedded Jasper

Use Embedded Tomcat

WebServlet with Servlet

WebServlet with GenericServlet

WebServlet with HttpServlet

Lesson-3: Reflection Framework

Java Reflection, Runtime

org.reflections:reflections

Controller, Service Annotation

Request Mapping Annotation

Get Types Annotated With

Get Declared Fields

Get Declared Constructors

Get Declared Methods

Lesson-4: DI Framework

Dependency Injection

org.reflections:reflections

Application Context

Bean Factory

@Inject, Constructor

Controller, Service

Bean Factory Test

Lesson-5: MVC Framework

Model View Controller

Dispatcher Servlet

Handler Mapping

Handler Adapter

View Resolver

Model and View

Request Method

Request Mapping Handler Mapping

Simple Controller Handler Adapter

Lesson-6: Spring Web MVC

Controller Annotation

RestController Annotation

MCV Container

Dependency Management

WebMvcAutoConfiguration

DispatcherServletAutoConfiguration

Tomcat , Web Application Server

Port Number, ServerProperties

Static, backend.fig, hello.html

Html Controller, Json Controller

Lesson-7: Dispatcher Servlet

WebMvcAutoConfiguration

DispatcherServletAutoConfiguration

DispatcherServlet

HandlerMapping

HandlerAdapter

ViewResolver

RequestHandledEventListener

HttpServletRequest

Lesson-8: Request Mappings

HTTP Method

HTTP Headers

Produces & Consumes

Single Path Variable

Multi Path Variable

Request Parameters

Request Header

Cookie Value

Shortcuts

Employee CRUD APIs

Lesson-9: Layered Architecture

N-Tier Architecture:

Presentation Layer

Service Layer

Repository Layer

Domain-Driven Design:

Domain Layer

Application Layer

Infrastructure Layer

config, controller

model / domain

repository, service

Lesson-10: Internationalization

Internationalization — i18n

resources/messages.properties

resources/messages_ru.properties

resources/messages_uz.properties

LanguageConfig

AcceptHeaderLocaleResolver

ResourceBundleMessageSource

Accept-Language — EN, RU, UZ

Translator, Locale

Lesson-11: Loading Initial Data

Entity + Data.sql

spring.jpa.defer-datasource-initialization

spring.sql.init.mode

Schema.sql + Data.sql

spring.jpa.hibernate.ddl-auto=none

Database Migrations

org.flywaydb:flyway-core

<Prefix><Version>__<Description>.sql

Lesson-12: RESTful HTTP Clients

RestClient — Core Spring

RestClient — Synchronous

RestClient — Blocking

WebClient — Spring WebFlux

WebClient — Asynchronous

WebClient — Non-blocking

OpenFeign — Spring Cloud

OpenFeign — Declarative

OpenFeign — Non-blocking

RestNetwork — Customized

Lesson-13: Schedule Cron Jobs

Timezone, JVM running

App running in UZB(+5) timezone

App running in UTC(+0) timezone

App running in KOR(+9) timezone

Scheduled with Fixed Delay

Scheduled with Fixed Rate

Cron Job — Once every 1 minute

Cron Job — Every day at 11:00 PM

Cron Job — Every 09:00 AM from Mon to Fri

Lesson-14: Recursion, Mapping

Bidirectional Relationship

Infinite Recursion Problem

JsonManagedReferences

JsonBackReferences

JsonIgnore

JsonIdentityInfo

Java Bean Mapper

MapStruct Gradle

MapStruct Maven

Request > Dto > Entity > Dto > Response

Lesson-15: OSIV, Transactions

Open Session in View

open-in-view: false

Transaction Scope

Controller, Service, Repository

Transaction Management

@Transactional — Throw Exception

@Transactional — Repository Save

@Transactional — Entity Setter

@Transactional — dontRollbackOn

Lesson-16: Spring Security I

1- Username & Generated Password

SecurityFilterChain, HttpSecurity

FormLogin, HttpBasic

2- InMemoryUserDetailsManager

Role(USER), Authorities(ROLE_USER)

SecurityContextHolder, Principle

3- UsernamePasswordAuthenticationToken

AuthenticationProvider, Authentication

RobotAuthenticationProvider

AuthorityUtils.createAuthorityList

4- Header Token

AlienAuthentication, Authentication

AlienAuthenticationProvider, AuthenticationProvider

AlienFilter, OncePerRequestFilter

HEADER_NAME = “x-alien-token”

Lesson-17: Spring Security II

User Entity with UserDetails

1- AuthenticationFilter

2- UsernamePasswordAuthenticationToken

3- AuthenticationManager

4- AuthenticationProvider

5- UserDetailsService

6- UserDetails, User

7- AuthenticationProvider

8- AuthenticationManager

9- AuthenticationFilter

10- SecurityContextHolder

Lesson-18: Spring Security III

User Entity without UserDetails

UserEntity, UserPrinciple

UserService, UserDetailsService

SecurityConfig, JwtFilter

SecurityFilterChain

AbstractHttpConfigurer::disable

SessionCreationPolicy.STATELESS

authorizeHttpRequests

DaoAuthenticationProvider

AuthenticationManager

ROLE_USER, ROLE_ADMIN

Lesson-19: Spring Security IV

Authentication Architecture

UserEntity, UserPrinciple

Access Token, Refresh Token

JwtSecretKey, JwtRefreshKey

SignIn Logic, SignOut Logic

ACCESS_TOKEN_EXPIRE_COUNT

REFRESH_TOKEN_EXPIRE_COUNT

Create Refresh Token

Load Refresh Token

Delete Refresh Token

Lesson-20: Localhost, HTTPS

Client, Web Server, WAS, DB

Web Server, NGINX, HTTPS

WAS, Localhost, HTTPS

mkcert -pkcs12 localhost

localhost.p12, application.yml

http://localhost:8080/

https://localhost:8080/

The hosts file as a domain

sudo vi /etc/hosts

www.justdoit.dev, application.yml

https://www.justdoit.dev:8080/

IT Project, Large-scale traffic

Lesson-1: The CAP Theorem

The CAP theorem, Brewer’s theorem

Consistency (C): All reads return the latest write

Availability (A): Every request gets a response

Partition Tolerance (P): Works despite network issues

Domain-Driven Design, Event-Driven Architecture

Monolithic, Microservice, Modulith Architectures

Monolithic: CA (Consistency + Availability)

Microservices: AP (Availability + Partition Tolerance)

Modulith: CA (Consistency + Availability)

Modulith: CP (Consistency + Partition Tolerance)

Lesson-2: Monolithic Architecture

Traditional way of building app

Easy deployment, debugging

User, Product, Order Entities

User, Product, Order Controllers

User, Product, Order Services

User, Product, Order Repositories

Centralized Database, PostgreSQL

Method calls within the application

Lesson-3: Microservice Architecture

Small and independent services

Database per service, PostgreSQL

USER-SERVICE, Eureka Client, 8081

PRODUCT-SERVICE, Eureka Client, 8082

ORDER-SERVICE, Eureka Client, 8083

Internal Communication, RESTful

RestClient, WebClient, FeignClient

Spring Cloud Netflix, Eureka Server, 8761

Spring Cloud Gateway, Eureka Client, 8080

Lesson-4: Modulith Architecture

Modular+Monolith=Modulith

Spring Modulith Structures

Packages, ApplicationModuleTest

ApplicationModules, Verify

DTOs with From and ToEntity

Private Repositories, DTOs, Service APIs

External Packages, package-info.java

ApplicationEventPublisher, Event Listener

Transactional, ApplicationModuleListener

Spring Modulith JPA, event_publication

Lesson-5: Real World Project — I

Java, SpringBoot, PostgreSQL, Gradle, Redis, Kafka, Git

Database for large data — Cassandra

Database for relational data — PostgreSQL

Database for data analysis — Druid

Database for non-relational data — Redis

Designing the Project Architecture

Spring Security and Its Features

Developing the Auth “Sign-Up” Feature

Developing the Auth “Sign-In” Feature

Developing the “User Info” Feature

Developing the “Create Post” Feature

Developing the “Update Post” Feature

Developing the “Delete Post” Feature

Developing the “My Posts” Feature

Developing the “Feed List” Feature

Lesson-6: Real World Project — II

Java, SpringBoot, PostgreSQL, Gradle, Redis, Kafka, Git

Developing the “Like” Feature

Developing the “Like Count” Feature

Developing the “Leave a Comment” Feature

Developing the “Comment List” Feature

Developing the Notification Feature

Analysis of Current Architectural Problems

Current Architectural Problems — Analysis I

Current Architectural Problems — Analysis II

Current Architectural Problems — Analysis III

Current Architectural Problems — Analysis IV

Solution to retrieve User entity from DB twice

Delete comments and likes when post is deleted

Lesson-7: Real World Project — III

Java, SpringBoot, PostgreSQL, Gradle, Redis, Kafka, Git

Solutions for Handling Large-Scale Traffic

Introduction to Redis for Real-Time Apps

Redis (https://redis.io/) vs Local Caching

Redis, In-memory, Key-Value, Commands,

Redis, Single Thread, Sentinel, Redis Cluster

UserDetails, loadUserByUsername, UserCache

Introduction to SSE for Real-Time Updates

Client, Request, Server, Response, Polling

Client, Request, Server, Response, Long-Polling

Client, Server, Request, Response, Web Socket

Client, Subscribe, Server, Server-Send Event (SSE)

Introduction to Kafka for Event Streaming

Apache Kafka, Producer, Broker, Consumer

Event Key, Topic, Partition, Consumer Group

Lesson-8: Traditional Server Setup (OS)

Client— WAS — DB

Browser— Tomcat — PostgreSQL

Client — Web Server — WAS — DB

Browser — NGINX — Tomcat — PostgreSQL

Operation System (Linux, Windows, Mac)

Run SpringBoot Application

Run SpringBoot with PostgreSQL

Run SpringBoot with PostgreSQL, Redis

Run SpringBoot with PostgreSQL, Redis, NGINX

Lesson-9: Modern Server Setup (Docker)

Host, Container, Linux, OS

OS (Linux, Windows, Mac)

App Store, Program, Process

DockerHub, Official Docker Images

Docker Commands, Image, Container

docker run -name test1 -d httpd

docker run -name test2 -d -p 8000:80 httpd

Dockerize SpringBoot Application

Individual containers (SpringBoot Application)

Multiple containers (SpringBoot, PostgreSQL)

Multiple containers (SpringBoot, PostgreSQL, Redis)

Multiple containers (SpringBoot, PostgreSQL, Redis, NGINX)

Dockerfile, docker-compose.yml

docker-compose up, docker-compose down

--

--

Responses (2)