SlideShare uma empresa Scribd logo
Need for Speed
Removing speed bumps in API Projects
Łukasz Chruściel
https://sm.ign.com/ign_in/screenshot/default/nfs-most-wanted_qxww.jpg
Introduction
Weavers, Sylius
Why do we need to thinks
about performance?
~ Amazon
“100ms Faster
=
1% More Revenue.”
The most common performance bottlenecks
0
15
30
45
60
Amount of queries to DB Cost of object serialization Latency Framework
5
4
28
56
Votes
Algorithmic complexity
Project structure
Problems 🎉
N+1
ORM anyone? 🧐
Product list
Let’s start small
{
"@context":"/api/contexts/Product",
"@id":"/api/products",
"@type":"hydra:Collection",
"hydra:totalItems":6,
"hydra:member":[
{
"@id":"/api/products/1",
"@type":"Product",
"id":1,
"name":"T-Shirt",
"price":1000
},
{
"@id":"/api/products/2",
"@type":"Product",
"id":2,
"name":"Trousers",
"price":5000
},
{
"“…“":"“…“"
}
]
}
Amount of products: 6
No associations between objects
Sample query on the left
O(1)
Order list
How many queries are executed here?
{
"@context": "/api/contexts/Order",
"@id": "/api/orders",
"@type": "hydra:Collection",
"hydra:totalItems": 3,
"hydra:member": [
{
"@id": "/api/orders/1",
"@type": "Order",
"id": 1,
"orderItems": [
"/api/order_items/1",
"/api/order_items/2"
]
},
{
“…”: “…“
}
]
}
Amount of orders: 3
Every order associated with 2 items
Sample query on the left
No total
fi
eld
O(N)
Order list with additional
fi
eld
How many queries are executed here?
{
"@context": "/api/contexts/Order",
"@id": "/api/orders",
"@type": "hydra:Collection",
"hydra:totalItems": 3,
"hydra:member": [
{
"@id": "/api/orders/1",
"@type": "Order",
"id": 1,
"orderItems": [
"/api/order_items/1",
"/api/order_items/2"
],
"total": 7000
},
{
“…”: “…“
}
]
}
Amount of orders: 3
Every order associated with 2 items
Sample query on the left
Added “total()” as a function of product
price and quantity of item
O(N*M) or O(N^2) 🚀
How to spot it?
How to
fi
x it?
Upfront data loading
#[ORMOneToMany(fetch: ‘EAGER')]
Eager loading
final class LoadItemsAndProductsExtension implements QueryCollectionExtensionInterface,
QueryItemExtensionInterface
{
private function apply(QueryBuilder $queryBuilder): void
{
$queryBuilder
->addSelect('oi', 'p')
->join(OrderItem::class, 'oi', Join::WITH, 'oi.originOrder = o')
->join(Product::class, 'p', Join::WITH, 'oi.product = p')
;
}
}
Custom query
So is single query an ultimate
solution?
⚠ Not so fast ⚠
Joins are expensive 💰
Serialisation
Problem vectors
Size of data
Process of
serialisation
Process of
serialisation
Serialisation process
oversimpli
fi
ed
[
'id' => 1,
'name' => 'T-Shirt',
'price' => '1000'
]
Application
Database
[
'id' => 1,
'name' => 'T-Shirt',
'price' => '1000'
]
Hydration 🧙
new Product()
Application
Database
[
'id' => 1,
'name' => 'T-Shirt',
'price' => '1000'
]
Hydration 🧙
new Product()
Application
Serialization ⚙
{
‘id': 1,
‘name': 'T-Shirt',
‘price': '1000'
}
Database Frontend app
[
'id' => 1,
'name' => 'T-Shirt',
'price' => '1000'
]
Hydration 🧙
new Product()
Application
Serialization ⚙
{
‘id': 1,
‘name': 'T-Shirt',
‘price': '1000'
}
Database Frontend app
🤡
Full stack vs API
Solution - Pre-computing
Sylius order
Saving serialised objects
View models doesn’t have to
be models 🤯
1. Store read models in key-value storage
2. Restore it by indexed key
Size of data
Entity lifecycle
oversimpli
fi
ed
Order
{
"items": [
{
"productName": "Mug",
"quantity": 3,
}
]
}
1. Cart
{
"items": [
{
"variant": "/api/v2/admin/product-variants/MUG
"productName": "Mug",
"id": @integer@,
"quantity": 3,
"unitPrice": 2000,
"originalUnitPrice": 2000,
"total": 6000,
"units": [
"/api/v2/admin/order-item-units/@integer@"
"/api/v2/admin/order-item-units/@integer@"
"/api/v2/admin/order-item-units/@integer@"
],
"fullDiscountedUnitPrice": 2000,
"subtotal": 6000
}
]
}
Order
1. Cart
2. Product details
{
"shippingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
"countryCode": "US",
"street": "Avenue",
"city": "New York",
"postcode": "90000"
},
"billingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
"countryCode": "US",
"street": "Avenue",
"city": "New York",
"postcode": "90000"
},
"items": [
{
"productName": "Mug",
1. Cart
2. Product details
3. Address
Order
Order
{
"payments": [
{
"@id": "/api/v2/admin/payments/@integer@",
"@type": "Payment",
"id": @integer@,
"method": "/api/v2/admin/payment-methods/CASH_
}
],
"shippingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
"countryCode": "US",
"street": "Avenue",
"city": "New York",
"postcode": "90000"
},
"billingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
1. Cart
2. Product details
3. Address
4. Payments
{
"shipments": [
{
"@id": "/api/v2/admin/shipments/@integer@",
"@type": "Shipment",
"id": @integer@,
"method": "/api/v2/admin/shipping-methods/UPS"
}
],
"payments": [
{
"@id": "/api/v2/admin/payments/@integer@",
"@type": "Payment",
"id": @integer@,
"method": "/api/v2/admin/payment-methods/CASH_
}
],
"shippingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
"countryCode": "US",
"street": "Avenue",
Order
1. Cart
2. Product details
3. Address
4. Payments
5. Shipments
{
"shipments": [
{
"@id": "/api/v2/admin/shipments/@integer@",
"@type": "Shipment",
"id": @integer@,
"method": "/api/v2/admin/shipping-methods/UPS"
}
],
"payments": [
{
"@id": "/api/v2/admin/payments/@integer@",
"@type": "Payment",
"id": @integer@,
"method": "/api/v2/admin/payment-methods/CASH_
}
],
"shippingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
"countryCode": "US",
"street": "Avenue",
Order
1. Cart
2. Product details
3. Address
4. Payments
5. Shipments
6. Available shippings
7. Available payments
8. Product categories
9. Images
10.…
1. Cart
2. Product details
3. Address
4. Payments
5. Shipments
{
"shipments": [
{
"@id": "/api/v2/admin/shipments/@integer@",
"@type": "Shipment",
"id": @integer@,
"method": "/api/v2/admin/shipping-methods/UPS"
}
],
"payments": [
{
"@id": "/api/v2/admin/payments/@integer@",
"@type": "Payment",
"id": @integer@,
"method": "/api/v2/admin/payment-methods/CASH_
}
],
"shippingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
"countryCode": "US",
"street": "Avenue",
1. Cart
2. Product details
3. Address
4. Payments
5. Shipments
6. Available shippings
7. Available payments
8. Product categories
9. Images
10.…
Performance📉
Order
{
"shipments": [
{
"@id": "/api/v2/admin/shipments/@integer@",
"@type": "Shipment",
"id": @integer@,
"method": "/api/v2/admin/shipping-methods/UPS"
}
],
"payments": [
{
"@id": "/api/v2/admin/payments/@integer@",
"@type": "Payment",
"id": @integer@,
"method": "/api/v2/admin/payment-methods/CASH_
}
],
"shippingAddress": {
"@id": "/api/v2/admin/addresses/@integer@",
"@type": "Address",
"firstName": "John",
"lastName": "Doe",
"countryCode": "US",
"street": "Avenue",
1. Cart
2. Product details
3. Address
4. Payments
5. Shipments
6. Available shippings
7. Available payments
8. Product categories
9. Images
10.…
Order
Size do matter
–ANGRY DEVELOPER
“BUT I NEED ALL THAT DATA 🤬”
Do you? 🧐
Solution - split data
{
"orderItems": [
{
"product": "/api/products/1",
"quantity": 4
},
{
"product": "/api/products/2",
"quantity": 1
}
],
"total": 9000
}
{
"orderItems": [
{
"product": {
"name": "test2",
"price": 1000
},
"quantity": 4
},
{
"product": {
"name": "Trousers",
"price": 5000
},
"quantity": 1
}
],
"total": 9000
}
Atomic objects (Edge Side API)
Do you need it all the time? 🧐
Solution - more variations
Property
fi
ltration
?properties[]=<property>&properties[<relation>][]=<property>
Property
fi
ltration
GraphQl
Property
fi
ltration
GraphQl
Vary header
–mdm web docs
“The Vary HTTP response header describes the parts of the request
message aside from the method and URL that in
fl
uenced the content
of the response it occurs in. Most often, this is used to create a
cache key when content negotiation is in use.”
Summary
Measure, measure, measure…
Top Gun: Maverick
Remember about algorithmic complexity of your queries
Do not hydrate too much data
Think out-of-the box of your “entities”
Thank you!

Mais conteúdo relacionado

Semelhante a ConFoo 2024 - Need for Speed: Removing speed bumps in API Projects

201410 2 fiware-orion-contextbroker
201410 2 fiware-orion-contextbroker201410 2 fiware-orion-contextbroker
201410 2 fiware-orion-contextbroker
FIWARE
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
PyCon Italia
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
崇之 清水
 

Semelhante a ConFoo 2024 - Need for Speed: Removing speed bumps in API Projects (20)

ATAGTR2017 Test Approach for Re-engineering Legacy Applications based on Micr...
ATAGTR2017 Test Approach for Re-engineering Legacy Applications based on Micr...ATAGTR2017 Test Approach for Re-engineering Legacy Applications based on Micr...
ATAGTR2017 Test Approach for Re-engineering Legacy Applications based on Micr...
 
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
 
Micro app-framework
Micro app-frameworkMicro app-framework
Micro app-framework
 
Micro app-framework - NodeLive Boston
Micro app-framework - NodeLive BostonMicro app-framework - NodeLive Boston
Micro app-framework - NodeLive Boston
 
Api's and ember js
Api's and ember jsApi's and ember js
Api's and ember js
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
Small pieces loosely joined
Small pieces loosely joinedSmall pieces loosely joined
Small pieces loosely joined
 
201410 2 fiware-orion-contextbroker
201410 2 fiware-orion-contextbroker201410 2 fiware-orion-contextbroker
201410 2 fiware-orion-contextbroker
 
Hands on SPA development
Hands on SPA developmentHands on SPA development
Hands on SPA development
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
 
Learn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdfLearn how to use API with 2 API examples.pdf
Learn how to use API with 2 API examples.pdf
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
REST API for your WP7 App
REST API for your WP7 AppREST API for your WP7 App
REST API for your WP7 App
 
PWA night vol.11 20191218
PWA night vol.11 20191218PWA night vol.11 20191218
PWA night vol.11 20191218
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
 
Wave Analytics: Developing Predictive Business Intelligence Apps
Wave Analytics: Developing Predictive Business Intelligence AppsWave Analytics: Developing Predictive Business Intelligence Apps
Wave Analytics: Developing Predictive Business Intelligence Apps
 
SyliusCon - Typical pitfalls of Sylius development.pdf
SyliusCon - Typical pitfalls of Sylius development.pdfSyliusCon - Typical pitfalls of Sylius development.pdf
SyliusCon - Typical pitfalls of Sylius development.pdf
 

Mais de Łukasz Chruściel

Mais de Łukasz Chruściel (19)

Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
ConFoo 2024 - Sylius 2.0, top-notch eCommerce for customizable solution
ConFoo 2024 - Sylius 2.0, top-notch eCommerce for customizable solutionConFoo 2024 - Sylius 2.0, top-notch eCommerce for customizable solution
ConFoo 2024 - Sylius 2.0, top-notch eCommerce for customizable solution
 
SymfonyLive Online 2023 - Is SOLID dead? .pdf
SymfonyLive Online 2023 - Is SOLID dead? .pdfSymfonyLive Online 2023 - Is SOLID dead? .pdf
SymfonyLive Online 2023 - Is SOLID dead? .pdf
 
Worldwide Software Architecture Summit'23 - BDD and why most of us do it wron...
Worldwide Software Architecture Summit'23 - BDD and why most of us do it wron...Worldwide Software Architecture Summit'23 - BDD and why most of us do it wron...
Worldwide Software Architecture Summit'23 - BDD and why most of us do it wron...
 
4Developers - Rozterki i decyzje.pdf
4Developers - Rozterki i decyzje.pdf4Developers - Rozterki i decyzje.pdf
4Developers - Rozterki i decyzje.pdf
 
4Developers - Sylius CRUD generation revisited.pdf
4Developers - Sylius CRUD generation revisited.pdf4Developers - Sylius CRUD generation revisited.pdf
4Developers - Sylius CRUD generation revisited.pdf
 
BoilingFrogs - Rozterki i decyzje. Czego się nauczyliśmy projektując API Syliusa
BoilingFrogs - Rozterki i decyzje. Czego się nauczyliśmy projektując API SyliusaBoilingFrogs - Rozterki i decyzje. Czego się nauczyliśmy projektując API Syliusa
BoilingFrogs - Rozterki i decyzje. Czego się nauczyliśmy projektując API Syliusa
 
What we've learned designing new Sylius API
What we've learned designing new Sylius APIWhat we've learned designing new Sylius API
What we've learned designing new Sylius API
 
How to optimize background processes.pdf
How to optimize background processes.pdfHow to optimize background processes.pdf
How to optimize background processes.pdf
 
SymfonyCon - Dilemmas and decisions..pdf
SymfonyCon - Dilemmas and decisions..pdfSymfonyCon - Dilemmas and decisions..pdf
SymfonyCon - Dilemmas and decisions..pdf
 
How to optimize background processes - when Sylius meets Blackfire
How to optimize background processes - when Sylius meets BlackfireHow to optimize background processes - when Sylius meets Blackfire
How to optimize background processes - when Sylius meets Blackfire
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
 
Sylius and Api Platform The story of integration
Sylius and Api Platform The story of integrationSylius and Api Platform The story of integration
Sylius and Api Platform The story of integration
 
Dutch php a short tale about state machine
Dutch php   a short tale about state machineDutch php   a short tale about state machine
Dutch php a short tale about state machine
 
A short tale about state machine
A short tale about state machineA short tale about state machine
A short tale about state machine
 
A short tale about state machine
A short tale about state machineA short tale about state machine
A short tale about state machine
 
BDD in practice based on an open source project
BDD in practice based on an open source projectBDD in practice based on an open source project
BDD in practice based on an open source project
 
Diversified application testing based on a Sylius project
Diversified application testing based on a Sylius projectDiversified application testing based on a Sylius project
Diversified application testing based on a Sylius project
 
Why do I love and hate php?
Why do I love and hate php?Why do I love and hate php?
Why do I love and hate php?
 

Último

Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
lolsDocherty
 
Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
ChloeMeadows1
 

Último (16)

Case study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptxCase study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptx
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
 
Topology of the Network class 8 .ppt pdf
Topology of the Network class 8 .ppt pdfTopology of the Network class 8 .ppt pdf
Topology of the Network class 8 .ppt pdf
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
Statistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfStatistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdf
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
Development Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appsDevelopment Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of apps
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresenceCyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirts
 
Premier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfPremier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdf
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirts
 

ConFoo 2024 - Need for Speed: Removing speed bumps in API Projects