SlideShare a Scribd company logo
Key learnings from
my refactor
journey.
Thiago Hora
The problem...
⬡ Maintainability
⬡ Hard to understand
⬡ Lack of test/lack of confidence to
change
⬡ Hard to evolve
⬡ Poor performance
How we approach that
1. Testing
2. Design and Abstractions
3. Experimentation
4. Queries and Indexes
5. Caching
6. Frameworks
7. Outcome
Testing
⬡ Make sure you have coverage
⬡ Any test is better than no test
⬡ There is no difference between test
code and production code
⬡ Refactoring also applies to test code
Design and Abstractions
⬡ Good code
Good code
Design and Abstractions
⬡ Good code
⬡ What does abstraction mean?
⬡ Where is it used?
⬡ What makes a good abstraction?
⬡ How to identify hidden abstractions?
⬡ You probably are going to fail at first
try
Testing/Code Refactor
Experimentation
⬡ Try different approaches
⬡ Apply changes incrementally
⬡ Use tools to measure the impact of
each change
⬡ Leverage feature toggles/flags
⬡ Discuss and share the results within
your team
Experimentation
Try and monitor
Number of time filter 1 is executed
Number of elements removed by filter 1
Number of time filter 2 is executed
Number of elements removed by filter 2
Latency before
Latency after first switch
Switching Back
After Switch definitively
Queries and Indexes
⬡ What is an index?
What is an index
What is an index
What is an index
What is an index
⬡ An ordered subset of data that represents
and provides the location of the register
⬡ B-tree
What is an index
What is an index
What is an index
What is an index
⬡ An ordered subset of data that represents
and provides the location of the register
⬡ B-tree
⬡ Fast search/Logarithmic running-time
Great, index everywhere
Of course not...
⬡ Indexes make the writes slower
⬡ Indexes take extra space
Queries and Indexes
⬡ What is an index?
⬡ What is an execution plan?
What is an execution plan?
⬡ It defines strategies to execute a query
⬡ Compare different possibilities
⬡ It does not guarantee the best option
What is an execution plan?
⬡ Type/Access Type
⬡ Scan strategies
⬡ Rows/Estimated rows affected
Type/Access Type
Type/Access Type
⬡ Const/eq_ref
⬡ Ref/Range/Index range scan
⬡ Index/Full index scan
⬡ All/Full table scan
Queries and Indexes
⬡ What is an index?
⬡ What is an execution plan?
⬡ Common mistakes
Common mistakes
⬡ Use functions on indexed columns
⬡ Index every column
⬡ Do not take into consideration the order of
the columns (in case of composite
indexes)
⬡ Sometimes only look for smaller row scan
number is not enough
⬡ Delegate all the logic the SQL query
⬡ Use an inequality operator and break the
SQL Improvements
Splitting/Simplifying
SQL Improvements
Splitting/Simplifying
SQL Improvements
Splitting/Simplifying
SQL Improvements
Index
Caching
⬡ What is caching?
⬡ Why to use it?
⬡ Where to use it?
⬡ How to implement caching?
How to implement caching?
How to implement caching?
How to implement caching?
Caching
⬡ What is caching?
⬡ Why to use it?
⬡ Where to use it?
⬡ How to implement caching?
⬡ Trade-offs
Trade-offs
⬡ Local vs distributed
⬡ Cache strategies
Cache strategies(Mention the
one we used)
/Write around
Cache strategies
Cache strategies
Cache strategies
Trade-offs
⬡ Local vs distributed
⬡ Cache strategies
⬡ Cache Policies
Cache application
Using cache
Cache application
Using cache
Frameworks
⬡ What is a Framework
⬡ Why do we use them?
⬡ Common mistakes
Common mistakes
⬡ Lack of understanding of the nuances
⬡ Do not read the documentation
⬡ Do not follow GitHub or community
involved
Framework Optimization
Configuration
1. Disable dirty check in hibernate for
read only resources
a. Set direct in the hibernate session
b. Use @Transaction(readOnly=true)
in Spring
Framework Optimization
Configuration
Framework Optimization
Configuration
Framework Optimization
Configuration
Framework Optimization
Configuration
Framework Optimization
Configuration
Outcome
Outcome
Thanks!
Links
⬡ https://www.slideshare.net/ChristianAntognini/indexes-
structuresplitsandfreespacemanagementinternals-otw2014
⬡ https://www.alibabacloud.com/blog/optimizing-mysql-composite-index-in-innodb_595057
⬡ https://www.youtube.com/watch?v=HubezKbFL7E
⬡ https://www.percona.com/blog/2012/11/23/full-table-scan-vs-full-index-scan-performance/
⬡ https://www.baeldung.com/spring-cache-tutorial
⬡ https://codeahoy.com/2017/08/11/caching-strategies-and-how-to-choose-the-right-one/
⬡ https://techbeacon.com/app-dev-testing/basic-abstraction-techniques-what-code-
reviewers-need-know
⬡ https://web.stanford.edu/~ouster/CS349W/lectures/abstraction.html
⬡ https://vladmihalcea.com/the-anatomy-of-hibernate-dirty-checking/
⬡ https://vladmihalcea.com/spring-read-only-transaction-hibernate-optimization/
⬡ https://www.baeldung.com/java-microbenchmark-harness
⬡ https://linux.die.net/man/1/ab#:~:text=ab%20is%20a%20tool%20for,installation%20is%20
capable%20of%20serving.

More Related Content

PPTX
Computational thinking
PPTX
Clean code - Getting your R&D on board
PDF
GRE - Computer Based Test
PDF
XPDS16: Patch review for non-maintainers - George Dunlap, Citrix Systems R&D...
PDF
TDD — Are you sure you properly test code?
PPTX
Code Review
PPTX
Every code coverage tool is measuring the wrong thing (on purpose)
PPTX
The Nature Of Patterns
Computational thinking
Clean code - Getting your R&D on board
GRE - Computer Based Test
XPDS16: Patch review for non-maintainers - George Dunlap, Citrix Systems R&D...
TDD — Are you sure you properly test code?
Code Review
Every code coverage tool is measuring the wrong thing (on purpose)
The Nature Of Patterns

What's hot (20)

PPTX
Unit Testing
PDF
Effective Unit Testing
PPTX
How to pass ArchiMate 3.1 Practitioner exam
PDF
Test Driven Development
PPTX
Expanding our Testing Horizons
PPTX
Lập trình hướng kiểm thử - Test Driven development
PPS
Test Cases Maintaining & Documenting
PPT
Best Practices of Software Development
PDF
Evolutionary Design - Refactoring Heuristics
PDF
Introducción a TDD
PPTX
Design Process
PDF
[Php vigo][talk] unit testing sucks ( and it's your fault )
PPT
An insight to test driven development and unit testing
PPTX
Helping Programmers Write Better Tests
PPTX
Advanced unit testing – real life examples and mistakes
PPTX
Defensive programming in php... by example
PDF
Writing Tests Effectively
PDF
Unit testing - An introduction
PPTX
Clean code
PPTX
Real Life Unit Testing
Unit Testing
Effective Unit Testing
How to pass ArchiMate 3.1 Practitioner exam
Test Driven Development
Expanding our Testing Horizons
Lập trình hướng kiểm thử - Test Driven development
Test Cases Maintaining & Documenting
Best Practices of Software Development
Evolutionary Design - Refactoring Heuristics
Introducción a TDD
Design Process
[Php vigo][talk] unit testing sucks ( and it's your fault )
An insight to test driven development and unit testing
Helping Programmers Write Better Tests
Advanced unit testing – real life examples and mistakes
Defensive programming in php... by example
Writing Tests Effectively
Unit testing - An introduction
Clean code
Real Life Unit Testing
Ad

Similar to Key learnings from my refactor journey. (20)

PDF
Unit testing (Exploring the other side as a tester)
PDF
Lessons Learned When Automating
PDF
Introduction to Test Driven Development
PPTX
Test case design techniques
PPTX
Test case design techniques
PPTX
Stop! you're testing too much
PPTX
STOP! You're Testing Too Much - Shawn Wallace
PPTX
Unit Testing and TDD 2017
PPTX
Code review
PPTX
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
PPTX
Random testing
PDF
Help! I need an empirical study for my PhD!
PDF
Basics of writing clean code
PPT
Iseb, ISTQB Static Testing
PDF
Test process - Important Concepts
PPS
ISTQB Foundation - Chapter 3
PPT
ISTQB / ISEB Foundation Exam Practice
PDF
Beyond "Quality Assurance"
PDF
Tdd in swift
Unit testing (Exploring the other side as a tester)
Lessons Learned When Automating
Introduction to Test Driven Development
Test case design techniques
Test case design techniques
Stop! you're testing too much
STOP! You're Testing Too Much - Shawn Wallace
Unit Testing and TDD 2017
Code review
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Random testing
Help! I need an empirical study for my PhD!
Basics of writing clean code
Iseb, ISTQB Static Testing
Test process - Important Concepts
ISTQB Foundation - Chapter 3
ISTQB / ISEB Foundation Exam Practice
Beyond "Quality Assurance"
Tdd in swift
Ad

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Key learnings from my refactor journey.