SlideShare a Scribd company logo
Refactoring Legacy
Code
Learnings from RedBubble
Paul Coia
What is Legacy Code?
Untested code
Dead code
Large classes/methods
Spaghetti architecture
Models too rigid to meet new
requirements
Product model
Available Option
Value
Product Type
Enumeration table
Product
Artwork
OptionOption Value
Print Size,
Frame Colour,
Matte Colour,
Frame Style
Small,
Medium,
Large,
Red,
etc.
FramedPrint
Enumeration table
Easy to add new products or options
 No new columns, just insert rows
No code changes
Can query against it
 “Find all artworks available on red t-shirts”
Populate web form elements easily
Domain model is in the DB
Product class is a generic type
What about domain logic?
„Instances‟ need a separate set of
tables
Buying a product
OptionOption Value
Available Option
Value
Product
Artwork
Product Type
Selected
Product
Selected
Option Value
Preparing the product form
framed_print = ProductType.find_by_name(“FramedPrint”)
# Get the Framed Print product
fp_product = artwork.products.detect do |p|
p.product_type == framed_print
end
aovs = fp_product.available_option_values
# Group these into the options
options_hash = {}
aovs.each do |aov|
options_hash[aov.option_value.option] << aov.option_value
end
# Order the option values, so we have S, M, L, etc.
# Populate form elements
SQL view
1. Load products by artwork_id
2. Load available_product_options by
product_id
3. Load option_values by option_value_id
4. Load options by option_id
Troublesome requirements
Some products have default
options
T-Shirt default colour and style
Options that are not constrained
Calendar start month
Inter-option constraints
Longsleeve Tee colours
Default options
Flag on available_product_option
Need to enforce one default per
option type
Render artwork with default
options
Rendering default options
Rendering the defaults
# Get the default product
tee_product = artwork.get_default_product
aovs = tee_product.available_option_values
defaults = aovs.select {|aov| aov.default? }
# Group these into the options (assuming one per option)
options_hash = {}
defaults.each do |aov|
options_hash[aov.option_value.option] << aov.option_value
end
# Need to validate that we have all required defaults
# and only one per option, etc.
SQL view
1. Load products by product_id
2. Load available_product_options by
product_id
3. Load option_values by option_value_id
4. Load options by option_id
 Same joins as the first example
Rendering lots of products!
Data volumes
0
50
100
150
200
250
300
350
Works Products Available Option Values
Millions
Inter option constraints
Roundneck T-shirts can have all
colours
V-Neck can only have a few
How do you model that in the DB?
Do you want to?
Original driver
Want to add new products weekly
Really?
Real-world constraints
Product preparation takes months
Cannot cover all eventualities
New products always required new
code anyway
Alternative approach
Model product types as classes
Define options and constraints (DSL)
Available products is a list of keys
on Artwork
Available product options is a hash
on the Artwork
So is the default options
Product class
class TShirtProduct
option Style, "mens", "T-Shirt"
option Style, "vneck", "V-Neck T-Shirt"
option Style, "longsleeve", "Long Sleeve T-Shirt"
option Style, "womens", "Girly Fitted T-Shirt"
option Style, "mhoodie", "Hoodie"
option Size, "xs", "XS"
option Size, "small", "Small"
option Size, "medium", "Medium”
...
AVAILABLE_COLORS = {
"mens" => all_colors,
"vneck" => [”black”, ”grey”, "navy", "white”]
}
end
Database model
Artwork
What have we gained?
An expressive, flexible product
model
Simpler code, overall
Actually easier to add products now
And easier to modify existing ones
Nearly 25% average speed increase
What have we lost?
“Find all red t-shirts”
Utilise a search engine
“How many large framed prints
have we sold?”
Reporting via Data Warehouse
Online product addition
100s of millions of rows from the DB!
Refactoring product model

More Related Content

Viewers also liked

Donors profiling softlab
Donors profiling softlabDonors profiling softlab
Donors profiling softlab
Softlab SpA
 
Binary tree
Binary treeBinary tree
Binary tree
raviahuja11
 
วิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลก
วิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลกวิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลก
วิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลกnutziip
 
Competencia liderazgo
Competencia liderazgoCompetencia liderazgo
Competencia liderazgoTito Perez
 
Cloud computing and business impact
Cloud computing and business impactCloud computing and business impact
Cloud computing and business impact
Jabbar Kiani
 

Viewers also liked (6)

Session hijacking
Session hijackingSession hijacking
Session hijacking
 
Donors profiling softlab
Donors profiling softlabDonors profiling softlab
Donors profiling softlab
 
Binary tree
Binary treeBinary tree
Binary tree
 
วิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลก
วิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลกวิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลก
วิชาคอมพรีเซ็นเรื่อง วิวัฒนาการอินเตอร์เน็ตของโลก
 
Competencia liderazgo
Competencia liderazgoCompetencia liderazgo
Competencia liderazgo
 
Cloud computing and business impact
Cloud computing and business impactCloud computing and business impact
Cloud computing and business impact
 

Similar to Refactoring product model

Le Wagon Tokyo | Build your Landing Page in 2 hours
Le Wagon Tokyo | Build your Landing Page in 2 hoursLe Wagon Tokyo | Build your Landing Page in 2 hours
Le Wagon Tokyo | Build your Landing Page in 2 hours
YannKlein2
 
Le Wagon - 2h Landing
Le Wagon - 2h LandingLe Wagon - 2h Landing
Le Wagon - 2h Landing
Boris Paillard
 
Physical Design and Development
Physical Design and DevelopmentPhysical Design and Development
Physical Design and Development
Er. Nawaraj Bhandari
 
Retail referencearchitecture productcatalog
Retail referencearchitecture productcatalogRetail referencearchitecture productcatalog
Retail referencearchitecture productcatalog
MongoDB
 
Sww 2008 Automating Your Designs Excel, Vba And Beyond
Sww 2008   Automating Your Designs   Excel, Vba And BeyondSww 2008   Automating Your Designs   Excel, Vba And Beyond
Sww 2008 Automating Your Designs Excel, Vba And Beyond
Razorleaf Corporation
 
2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload
Prof. Wim Van Criekinge
 
Html css
Html cssHtml css
Html css
John Felix
 
Introduction to Advanced Product Options
 Introduction to Advanced Product Options  Introduction to Advanced Product Options
Introduction to Advanced Product Options
Ketan Raval
 
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docxBUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
humphrieskalyn
 
Le Wagon - Build your Landing Page in 2 hours
Le Wagon - Build your Landing Page in 2 hoursLe Wagon - Build your Landing Page in 2 hours
Le Wagon - Build your Landing Page in 2 hours
Sandrine Ayral
 
Customized Retail audit
Customized Retail auditCustomized Retail audit
Customized Retail audit
Mohammed Moghazy
 
Le Wagon - Landing page
Le Wagon - Landing pageLe Wagon - Landing page
Le Wagon - Landing page
Kévin Chavanne
 
Building Sustainable Design Systems
Building Sustainable Design SystemsBuilding Sustainable Design Systems
Building Sustainable Design Systems
UXDXConf
 
Handout7 html forms
Handout7 html formsHandout7 html forms
Handout7 html forms
Nadine Guevarra
 
AI Builder Deep Dive Power BI User Group Washington DC
AI Builder Deep Dive Power BI User Group Washington DCAI Builder Deep Dive Power BI User Group Washington DC
AI Builder Deep Dive Power BI User Group Washington DC
Rebekka Aalbers-de Jong
 
AI Builder Deep Dive
AI Builder Deep DiveAI Builder Deep Dive
AI Builder Deep Dive
Rebekka Aalbers-de Jong
 
Boosting Product Categorization with Machine Learning
Boosting Product Categorization with Machine LearningBoosting Product Categorization with Machine Learning
Boosting Product Categorization with Machine Learning
Amadeus Magrabi
 
Le Wagon Tokyo - 2 hours landing page
Le Wagon Tokyo - 2 hours  landing pageLe Wagon Tokyo - 2 hours  landing page
Le Wagon Tokyo - 2 hours landing page
Hidehiro Nagaoka
 
AI Builder Deep dive Super Power Saturday London 2020
AI Builder Deep dive Super Power Saturday London 2020AI Builder Deep dive Super Power Saturday London 2020
AI Builder Deep dive Super Power Saturday London 2020
Rebekka Aalbers-de Jong
 
Html 5
Html 5Html 5

Similar to Refactoring product model (20)

Le Wagon Tokyo | Build your Landing Page in 2 hours
Le Wagon Tokyo | Build your Landing Page in 2 hoursLe Wagon Tokyo | Build your Landing Page in 2 hours
Le Wagon Tokyo | Build your Landing Page in 2 hours
 
Le Wagon - 2h Landing
Le Wagon - 2h LandingLe Wagon - 2h Landing
Le Wagon - 2h Landing
 
Physical Design and Development
Physical Design and DevelopmentPhysical Design and Development
Physical Design and Development
 
Retail referencearchitecture productcatalog
Retail referencearchitecture productcatalogRetail referencearchitecture productcatalog
Retail referencearchitecture productcatalog
 
Sww 2008 Automating Your Designs Excel, Vba And Beyond
Sww 2008   Automating Your Designs   Excel, Vba And BeyondSww 2008   Automating Your Designs   Excel, Vba And Beyond
Sww 2008 Automating Your Designs Excel, Vba And Beyond
 
2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload2018 03 27_biological_databases_part4_v_upload
2018 03 27_biological_databases_part4_v_upload
 
Html css
Html cssHtml css
Html css
 
Introduction to Advanced Product Options
 Introduction to Advanced Product Options  Introduction to Advanced Product Options
Introduction to Advanced Product Options
 
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docxBUSI 301 Book Review RubricScoreCommentsResearch 25.docx
BUSI 301 Book Review RubricScoreCommentsResearch 25.docx
 
Le Wagon - Build your Landing Page in 2 hours
Le Wagon - Build your Landing Page in 2 hoursLe Wagon - Build your Landing Page in 2 hours
Le Wagon - Build your Landing Page in 2 hours
 
Customized Retail audit
Customized Retail auditCustomized Retail audit
Customized Retail audit
 
Le Wagon - Landing page
Le Wagon - Landing pageLe Wagon - Landing page
Le Wagon - Landing page
 
Building Sustainable Design Systems
Building Sustainable Design SystemsBuilding Sustainable Design Systems
Building Sustainable Design Systems
 
Handout7 html forms
Handout7 html formsHandout7 html forms
Handout7 html forms
 
AI Builder Deep Dive Power BI User Group Washington DC
AI Builder Deep Dive Power BI User Group Washington DCAI Builder Deep Dive Power BI User Group Washington DC
AI Builder Deep Dive Power BI User Group Washington DC
 
AI Builder Deep Dive
AI Builder Deep DiveAI Builder Deep Dive
AI Builder Deep Dive
 
Boosting Product Categorization with Machine Learning
Boosting Product Categorization with Machine LearningBoosting Product Categorization with Machine Learning
Boosting Product Categorization with Machine Learning
 
Le Wagon Tokyo - 2 hours landing page
Le Wagon Tokyo - 2 hours  landing pageLe Wagon Tokyo - 2 hours  landing page
Le Wagon Tokyo - 2 hours landing page
 
AI Builder Deep dive Super Power Saturday London 2020
AI Builder Deep dive Super Power Saturday London 2020AI Builder Deep dive Super Power Saturday London 2020
AI Builder Deep dive Super Power Saturday London 2020
 
Html 5
Html 5Html 5
Html 5
 

Recently uploaded

What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 

Recently uploaded (20)

What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 

Refactoring product model

  • 2.
  • 3. What is Legacy Code? Untested code Dead code Large classes/methods Spaghetti architecture Models too rigid to meet new requirements
  • 5. Available Option Value Product Type Enumeration table Product Artwork OptionOption Value Print Size, Frame Colour, Matte Colour, Frame Style Small, Medium, Large, Red, etc. FramedPrint
  • 6. Enumeration table Easy to add new products or options  No new columns, just insert rows No code changes Can query against it  “Find all artworks available on red t-shirts” Populate web form elements easily
  • 7. Domain model is in the DB Product class is a generic type What about domain logic? „Instances‟ need a separate set of tables
  • 8. Buying a product OptionOption Value Available Option Value Product Artwork Product Type Selected Product Selected Option Value
  • 9. Preparing the product form framed_print = ProductType.find_by_name(“FramedPrint”) # Get the Framed Print product fp_product = artwork.products.detect do |p| p.product_type == framed_print end aovs = fp_product.available_option_values # Group these into the options options_hash = {} aovs.each do |aov| options_hash[aov.option_value.option] << aov.option_value end # Order the option values, so we have S, M, L, etc. # Populate form elements
  • 10. SQL view 1. Load products by artwork_id 2. Load available_product_options by product_id 3. Load option_values by option_value_id 4. Load options by option_id
  • 11. Troublesome requirements Some products have default options T-Shirt default colour and style Options that are not constrained Calendar start month Inter-option constraints Longsleeve Tee colours
  • 12. Default options Flag on available_product_option Need to enforce one default per option type Render artwork with default options
  • 14. Rendering the defaults # Get the default product tee_product = artwork.get_default_product aovs = tee_product.available_option_values defaults = aovs.select {|aov| aov.default? } # Group these into the options (assuming one per option) options_hash = {} defaults.each do |aov| options_hash[aov.option_value.option] << aov.option_value end # Need to validate that we have all required defaults # and only one per option, etc.
  • 15. SQL view 1. Load products by product_id 2. Load available_product_options by product_id 3. Load option_values by option_value_id 4. Load options by option_id  Same joins as the first example
  • 16. Rendering lots of products!
  • 18. Inter option constraints Roundneck T-shirts can have all colours V-Neck can only have a few How do you model that in the DB? Do you want to?
  • 19. Original driver Want to add new products weekly Really? Real-world constraints Product preparation takes months Cannot cover all eventualities New products always required new code anyway
  • 20. Alternative approach Model product types as classes Define options and constraints (DSL) Available products is a list of keys on Artwork Available product options is a hash on the Artwork So is the default options
  • 21. Product class class TShirtProduct option Style, "mens", "T-Shirt" option Style, "vneck", "V-Neck T-Shirt" option Style, "longsleeve", "Long Sleeve T-Shirt" option Style, "womens", "Girly Fitted T-Shirt" option Style, "mhoodie", "Hoodie" option Size, "xs", "XS" option Size, "small", "Small" option Size, "medium", "Medium” ... AVAILABLE_COLORS = { "mens" => all_colors, "vneck" => [”black”, ”grey”, "navy", "white”] } end
  • 23. What have we gained? An expressive, flexible product model Simpler code, overall Actually easier to add products now And easier to modify existing ones Nearly 25% average speed increase
  • 24. What have we lost? “Find all red t-shirts” Utilise a search engine “How many large framed prints have we sold?” Reporting via Data Warehouse Online product addition 100s of millions of rows from the DB!

Editor's Notes

  1. Legacy code slows down feature developmentWe all write itSo there’s a lot around
  2. Need to determine what the product represents before we can do anything with it.For example, we need to render it differently
  3. Joining 4 tables together
  4. Each thumbnail requires the same 4 tables joined
  5. Each work has multiple products, and each has multiple available options
  6. In 4 years, RedBubble has 11 product types.Sourcing suppliers, defining the specifications and getting samples all was time consuming.The application needed to know how to provision, configure and render the product.Genericity ended up getting in the way.
  7. Selected options and defaults are on the artworkOptions are modelled in a code (DSL)Rendering a default view requires only the loading of one record
  8. Every line of code had a reason for existenceChallenge existing models for every new requirement