@SmaineDev

afup

๐ŸฃEngineering Manager๐Ÿฅ

๐Ÿš€ www.smaine.me

ย  ย  ย @SmaineDev

๐Ÿ–Š ย smaine-milianni.medium

ย  ย  ย  ismail1432

ย  ย  ย smainemilianni

๐Ÿฟ github.com/ismail1432/conferences

Smaรฏne Milianni

@SmaineDev

BLUE - GREENย 

DEPLOYMENT

@SmaineDev

Production Version

Release Version

Version N+1

Version N

@SmaineDev

Production Version

Version N

Release Version

Version N+1

@SmaineDev

๐Ÿ—‘๏ธ

Realease Version

Version N+1

Productionย Version

Version N

@SmaineDev

๐Ÿ—‘๏ธ

What is ZDD* ?

ZDD*: Zero downtime deployment but you already know this ๐Ÿ˜„

Why and what is ZDD ?

โœ… Deploy a new release without Downtime

Why and what is ZDD ?

โœ… Deploy a new release without Downtime

๐Ÿš€ Release at any time (even on Friday ๐Ÿคช)

Why and what is ZDD ?

โœ… Deploy a new release without Downtime

๐Ÿš€ Release at any time (even on Friday ๐Ÿคช)

๐Ÿ˜ Release is transparent for the users

Why and what is ZDD ?

โœ… Deploy a new release without Downtime

๐Ÿš€ Release at any time (even on Friday ๐Ÿคช)

๐Ÿ˜ Release is transparent for the users

๐ŸŽ‰ No more waking up at dawn ๐Ÿ“ or at night ๐ŸŒ™

Why and what is ZDD ?

โœ… Deploy a new release without Downtime

๐Ÿš€ Release at any time (even on Friday ๐Ÿคช)

๐Ÿ˜ Release is transparent for the users

๐ŸŽ‰ No more waking up at dawn ๐Ÿ“ or at night ๐ŸŒ™

โฎ๏ธ Make the rollback easier

@SmaineDev

ZDD Golden Rules ๐Ÿ“–

1๏ธโƒฃ The changes should be backward compatible!

ย 

2๏ธโƒฃ The changes should be done per release.

@SmaineDev

ZDD Golden Rules ๐Ÿ“–

๐Ÿ”€ Backward compatible

๐Ÿพ Done per release

@SmaineDev

Backward Compatibility

Version N + 1

Version N

WWW

๐Ÿ“† Change per release

Version N

release tag 7.10.24

Version N + 1

release tag 8.10.24

Version N + 2

release tag 9.10.24

@SmaineDev

No panic, it's just a release

@SmaineDev

Start Deployment โ–ถ๏ธ

Deployย โ–ถ๏ธ

Version N

@SmaineDev

Deployย โณ

Version N

Deployment in progress โณ

Deployย โœ…

Version N

Version N+1

Deployment done without downtime ๐ŸŽ‰

@SmaineDev

Deployย Failย ๐Ÿ˜ฑ

Version N

Version N+1

๐Ÿ‘ŒApp is still up, event the deploy failed

Version N

@SmaineDev

Deployย โœ…

Version N

Version N+1

๐Ÿ”™ Rollback easy

Version N+1

@SmaineDev

๐Ÿ”™ Rollback easy

Principal Engineer

@Back Market

@SmaineDev

ZDD in practice ๐Ÿฅ‹

@SmaineDev

ZDD in practice ๐Ÿฅ‹

๐Ÿ—ƒ๏ธ Database

โœ‰๏ธ Message brokers

โ˜๏ธ API

@SmaineDev

Database

Add a `Not Null`column

Version N

Version N+1

Version N

Version N+1

DEPLOYMENTย ๐Ÿš€

Code version Nย is alive with

Database schema version N+1

@SmaineDev

Release 1๏ธโƒฃ

Add the column nullable

The code should write in the column

Release 2๏ธโƒฃ

Update existing rows with a value and add the NOT NULL constraint

Release 1๏ธโƒฃ

  • Add the column and make it nullable
  • Codebase write in the column โœ๐Ÿฟ

Release 2๏ธโƒฃ

  • Update null rows with default value
  • Add the not null constraints ๐Ÿ”

๐Ÿ’ก Prepare all pull request to not forget

@SmaineDev

  • DELETE a column
  • UPDATE a column type
  • RENAME a column
  • ADD a NOT NULL constraint
  • ...

Database

TOOLING โš’๏ธ

TOOLING โš’๏ธ

Make your migrations safer:

  • by preventing lock
  • using a retry strategy

ย 

$ bin/symfony console d:m:m

[notice] Migrating up to DoctrineMigrations\Version20231224200000
09:30:38 WARNING   [app] (1/3) Lock timeout reached: retrying in 10 seconds...
["sql" => "ALTER TABLE test_retry ADD COLUMN name text DEFAULT NULL"]
09:30:51 WARNING   [app] (2/3) Lock timeout reached: retrying in 10 seconds... ["sql" => "ALTER TABLE test_retry ADD COLUMN name text DEFAULT NULL"]
09:30:51 WARNING   [app] (3/3) Lock timeout reached: retrying in 10 seconds... ["sql" => "ALTER TABLE test_retry ADD COLUMN name text DEFAULT NULL"]


[error] Migration DoctrineMigrations\Version20231224200000 failed during Execution. 
Error: "An exception occurred while executing a query: SQLSTATE[55P03]: Lock not available: 7 
ERROR:  canceling statement due to lock timeout" 
09:31:17 CRITICAL  [console] Error thrown while running command "'d:m:m'". 

@SmaineDev

ASSERT ZDD COMPLIANCE

Manual test ๐Ÿ–ฑ๏ธ

Run SQL migration of theย NEXT RELEASE on the PRODUCTION version

@SmaineDev

ASSERT ZDD COMPLIANCE

2๏ธโƒฃ Checkout on the `production` branch & run tests

๐Ÿ’กAdd a specific job in your CI

1๏ธโƒฃ Load the DB schema in the branch you want to merge

Version N

Version N+1

๐Ÿง  Add an environment var to allow failure when needed

MESSAGE BROKERS

@SmaineDev

Serialization

Deserialization

Publisher

Consumer

MESSAGE BROKERS

Version N

@SmaineDev

Publisher

Version N

๐Ÿ›‘ Consumers are stopped during the deployment

๐Ÿš€ Deploy Version N+1

MESSAGE BROKERS

Serialization

Deserialization

Publisher

Consumer

Version N

Version N+1

Serialization

Deserialization

Publisher

Consumer

Version N

Version N+1

Publisher

Consumer

Version N

Version N+1

  • Set a default value
  • write in the property

Publisher

Consumer

Version N+1

Release 1๏ธโƒฃ

Version N+2

Release 2๏ธโƒฃ

  • Set a default value
  • Write in the property
  • Remove default value

MESSAGE BROKERS

Remove a property

Rename the class

Update property type

...

ASSERT ZDD COMPLIANCE

Manual test ๐Ÿ–ฑ๏ธ

Publish messages withย PRODUCTION code version and consume them with the NEXT RELEASE version

ASSERT ZDD COMPLIANCE

2๏ธโƒฃ Consume them with the version of the branch you want to merge

๐Ÿ’กAdd a specific job in your CI

1๏ธโƒฃ Publish messages with the production version

๐Ÿ’กAdd a specific job in your CI

๐Ÿ–Š๏ธ Helpers to generate message(s)

๐Ÿ—ƒ๏ธ Validate messages can be unserialized

TOOLING โš’๏ธ

FRONT

BACKEND

๐Ÿ’”

FRONT

BACKEND

Version N

Version N+1

๐Ÿ’ฅ

  • Make a property required
  • Removeย a property
  • Updateย or Removeย the path
  • ...

BACKEND

Addย a new requiredย property

Make the property required

FRONTEND

Writeย in the property

BACKEND

Make the property optional

Release 1๏ธโƒฃ

Release 2๏ธโƒฃ

FRONTEND

๐Ÿ˜ด

BACKEND

Removeย a property

Remove the property

FRONTEND

Stop writingย in the property

BACKEND

Make the property optional

Release 1๏ธโƒฃ

Release 2๏ธโƒฃ

FRONTEND

๐Ÿ˜ด

BACKEND

Renameย an endpoint

Removeย the old endpoint

FRONTEND

BACKEND

Addย the newย endpoint

Release 1๏ธโƒฃ

Release 2๏ธโƒฃ

Use the new endpoint

FRONTEND

๐Ÿ˜ด

BACKEND

Version N

Version N+1

  • Writeย in the new property
  • Don't sendย the property
  • Useย the new path
  • ...

๐Ÿค

  • Add the property optional
  • Remove usage ofย property
  • Keepย the old path
  • ...

FRONT

FRONT

BACKEND

TOOLING โš’๏ธ

๐Ÿ‘‰๐Ÿฝ https://github.com/thephpleague/openapi-psr7-validator

1๏ธโƒฃ Define API contract (`yaml` or `json`)

2๏ธโƒฃ Generate Front class from the file

3๏ธโƒฃ Assert that your API respect the OAS

ย ๐Ÿ’ก OpenAPI Specification

https://swagger.io/specification/

ZDD LIMITATIONS ๐Ÿ›‘

๐Ÿ“… Make sense if your release frequently

ZDD LIMITATIONS ๐Ÿ›‘

๐Ÿ“… Make sense if your release frequently

โน Critical changes still need maintenance

ZDD LIMITATIONS ๐Ÿ›‘

๐Ÿ“… Make sense if your release frequently

โน Critical changes still need maintenance

๐Ÿ›น System unstable until the last step

ZDD LIMITATIONS ๐Ÿ›‘

๐Ÿ“… Make sense if your release frequently

โน Critical changes still need maintenance

๐Ÿ›น System unstable until the last step

๐Ÿง  Most changes require reflection and discipline

ZDD LIMITATIONS ๐Ÿ›‘

Implement ZDD in your team ๐Ÿซต๐Ÿฟ

Implement ZDD in your team ๐Ÿซต๐Ÿฟ

๐Ÿ‰ Educate your team (workshops, code review...)

Implement ZDD in your team ๐Ÿซต๐Ÿฟ

๐Ÿ‰ Educate your team (workshops, code review...)

๐Ÿ“ Documentation (reference each case)

Implement ZDD in your team ๐Ÿซต๐Ÿฟ

๐Ÿ‰ Educate your team (workshops, code review...)

๐Ÿ“ Documentation (reference each case)

๐Ÿงช Learn from your failures (postmortems, feedback...)

Implement ZDD in your team ๐Ÿซต๐Ÿฟ

๐Ÿ‰ Educate your team (workshops, code review...)

๐Ÿ“ Documentation (reference each case)

๐Ÿงช Learn from your failures (postmortems, feedback...)

โœ… Tests

Implement ZDD in your team ๐Ÿซต๐Ÿฟ

๐Ÿ‰ Educate your team (workshops, code review...)

๐Ÿ“ Documentation (reference each case)

๐Ÿงช Learn from your failures (postmortems, feedback...)

โœ… Tests

๐Ÿฆธโ€โ™‚๏ธ Assign a ZDD hero

Feedbacks๐Ÿ‘‡

QUESTION