Slide 1

Slide 1 text

Building Durable, Performant Systems Integrations at Scale Thayer Luscian @ Above The Fray ×

Slide 2

Slide 2 text

Head of Engineering abovethefray.io • thayer.dev Based in Lancaster, PA Has a cat (pictured) As of July, has a wife (not pictured) ThayerLuscian.phtml

Slide 3

Slide 3 text

Platform-agnostic (but I 🧡 Magento) Architecture-agnostic (mostly) In context of two systems Assumes a “blind” integrator Ground rules 1 2 3 4

Slide 4

Slide 4 text

Separation of concerns

Slide 5

Slide 5 text

Direct connection (Magento does the heavy lifting) pub sub pub sub

Slide 6

Slide 6 text

What happens when Magento goes down? pub sub pub sub ?

Slide 7

Slide 7 text

What happens when D365 goes down? pub sub pub sub ?

Slide 8

Slide 8 text

Stability A system’s ability to perform by consistently maintaining stasis Keeping the lights on Durability A system’s ability to perform consistently despite loss of stasis Stasis A state of equilibrium, wherein “it’s all chill bruv” (remember, from biology class?)

Slide 9

Slide 9 text

Beep beep! Here comes the message bus! pub sub pub sub A B

Slide 10

Slide 10 text

Almost anything can be a message bus, if you only believe… pub sub pub sub A B

Slide 11

Slide 11 text

… but sometimes, it does take a little extra work. pub sub pub sub A B SFTP

Slide 12

Slide 12 text

Neither snow nor rain nor heat nor gloom of night— pub sub pub sub A B ?

Slide 13

Slide 13 text

Double-decker message bus! pub sub pub sub A sub pub B C D

Slide 14

Slide 14 text

Publish, enqueue, consume

Slide 15

Slide 15 text

Entities & events ● Integrations synchronize entities (nouns) ● Integrations are driven by events (verbs) product updated product sales order placed sales order Transactional Non-transactional entity event

Slide 16

Slide 16 text

Event listener (observer) ● Make sure to pick the right event! ● A (welcome) exception to the rule ● Save publication status in DB! Cron job ● Use these sparingly and efficiently ● Can bring other performance issues ● Make sure you know what you’re doing Webhooks ● Should be paired with a “full load” ● Availability is a toss-up, since you’re already dealing with a closed system Polling ● Extra care needed to ensure efficiency ● Requires extra work for change tracking ● Should be paired with a “full load” How do we know when events happen? Active Passive Closed system Open system

Slide 17

Slide 17 text

We always know what Magento’s up to pub B app/code sales order placed Mind palace Great unknown

Slide 18

Slide 18 text

APIs: a window into another world pub B app/code sales order placed Mind palace Great unknown API

Slide 19

Slide 19 text

Most systems are closed (and sometimes you should treat them that way anyway).

Slide 20

Slide 20 text

Magento isn’t really special pub B X++ product updated Someone else’s mind palace “The shopping cart” API

Slide 21

Slide 21 text

We’ll take what we can get pub B app/code sales order placed Mind palace Great unknown something something ibm? DB2

Slide 22

Slide 22 text

Use the Force, Luke pub app/code sales order placed Mind palace Not-so-great unknown API pub microservice API I/F A B web hook

Slide 23

Slide 23 text

Some entities must be polled because they change too often.

Slide 24

Slide 24 text

Consuming is a little easier! sub app/code product update Mind palace Not-so-great unknown API sub microservice API I/F A B

Slide 25

Slide 25 text

Be careful where you step! INSERT Create a new entity, even if an identical one already exists (not idempotent) REPLACE Apply all values as provided (including blank) to all fields for an existing entity (idempotent) MERGE Apply certain provided values to specified fields for an existing entity (idempotent) Idempotent Has the same effect, no matter how many times you do it POST PATCH PUT (technically)

Slide 26

Slide 26 text

Building it right

Slide 27

Slide 27 text

Rule #1 Solve “data” problems with logic solutions. State Region Equivalent entities, common key ISO 3166-2

Slide 28

Slide 28 text

Rule #2 Keep all business logic separate from the integration layer. Warehouse A = 15 Warehouse B = 12 qty = whA + whB qty: 27 Quantity = 27 Warehouse A = 15 Warehouse B = 12 whA: 15 whB: 12 Warehouse A = 15 Warehouse B = 12 qty = whA + whB Quantity = 27 Correct Incorrect ERP Integration Magento

Slide 29

Slide 29 text

Rule #3 Log errors in all three layers, and keep at least one copy of payloads. → ~/var/log tail -f integration.log Jun 16 14:12:01admin user [email protected] not found with role "Sales Rep" thayer - ssh - [email protected]

Slide 30

Slide 30 text

Rule #4 Optimize publishers and consumers to use the fewest possible resources. GET https://erp.acme.co/api/orders?status=open GET https://erp.acme.co/api/orders?status=open &updated_start=2023-06-16T23:49:00Z ↑ 5,000 orders loaded to memory & filtered ↓ 35 orders loaded to memory, no filtering needed &updated_end=2023-06-16T23:50:00Z

Slide 31

Slide 31 text

abovethefray.io • thayer.dev Questions?