30
Stories from the trenches It’s just a bloody one way synchronisation between two systems. How hard can it be? Melbourne Alt.Net Mercury Project 23 February 2016 Shohre Mansouri 1

Alt.Net Presentation

Embed Size (px)

Citation preview

Page 1: Alt.Net Presentation

Stories from the trenchesIt’s just a bloody one way synchronisation between two systems. How hard can it be?

Melbourne Alt.NetMercury Project

23 February 2016

Shohre Mansouri1

Page 2: Alt.Net Presentation

how the battle started

2

Page 3: Alt.Net Presentation

3

Page 4: Alt.Net Presentation

First Attack

4

Page 5: Alt.Net Presentation

Exsiting wcf methods for useShipmentId[] GetUpdatedShipments(UpdateAtFrom, UpdateAtTo)

Shipment GetShipment(ShipmentId)

5

Page 6: Alt.Net Presentation

Use “UpdateAt” as means of getting the updates

Every 2 minutes:GetUpdatedShipmentsCommand(From, DateTime.UtcNow)Handler sends: GetShipmentCommand(ShipmentId)

ShipmentId UpdateAt

Shipment1 12:00:01

Shipment2 12:00:02

Shipment3 12:00:02

Shipment4 12:00:03

Shipment5 12:00:04

6

Page 7: Alt.Net Presentation

Use “UpdateAt” as means of getting the updates

Every 2 minutes:GetUpdatedShipmentsCommand(From, DateTime.UtcNow)Every 1 minute:GetUpdatedShipmentsFromDatabaseCommand() -> GetShipment(ShipmentId)

ShipmentId UpdateAt

Shipment1 12:00:01

Shipment1 12:00:02

Shipment2 12:00:02

Shipment1 12:00:03

Shipment1 12:00:04

7

Page 8: Alt.Net Presentation

No Unbounded sets

Every 2 minutes:GetUpdatedShipmentsFromWcfCommand(From, DateTime.UtcNow, PageSize)Every 1 minute:GetUpdatedShipmentsFromDatabaseCommand(PageSize)

ShipmentId UpdateAt

Shipment1 12:00:01

Shipment1 12:00:02

Shipment2 12:00:02

Shipment1 12:00:03

Shipment1 12:00:04

8

Page 9: Alt.Net Presentation

Sample

UpdatedAt => From && UpdatedAt < To

ShipmentId UpdateAt

1 Shipment3 12:00:01 x2 Shipment1 12:00:02 x x3 Shipment2 12:00:02 x x4 Shipment1 12:06:04 X

5 Shipment2 12:06:06 X X

6 Shipment3 12:08:00 X

From To (Now) PageSize

12:00:00 12:02:00 3

12:00:02 12:04:00 3

12:04:00 12:06:00 3

12:06:00 12:08:00 3

12:08:00 12:10:00 3

12:10:00 12:12:00 3

9

Page 10: Alt.Net Presentation

Sample ShipmentId UpdateAt

1 Shipment3 12:00:01 x x x X2 Shipment1 12:00:01 x x x X3 Shipment2 12:00:01 x x x X4 Shipment1 12:00:01

5 Shipment2 12:00:01

6 Shipment3 12:06:06

From To (Now) PageSize

12:00:00 12:02:00 3

12:00:01 12:04:00 3

12:00:01 12:06:00 3

12:00:01 12:08:00 3

12:00:01 12:10:00 3

UpdatedAt > From && UpdatedAt < To

10

Page 11: Alt.Net Presentation

There was a bug!

11

Page 12: Alt.Net Presentation

This other WCF methodGetUpdatedShipments(FromVersion, PageSize)

Version is a sequential integer assigned to each update!

12

Page 13: Alt.Net Presentation

Use Version as means of getting the updates

Every 2 minutes:GetUpdatedShipmentsCommand(StartVersion, PageSize)Every 1 minute:GetUpdateShipmentFromDatabaseCommand(PageSize)

ShipmentId Version

Shipment1 100

Shipment1 104

Shipment2 106

Shipment1 111

Shipment1 112

13

Page 14: Alt.Net Presentation

Shipments have filesConsistency of the shipments and document!

Saga: For handling long-running business processes

“NServiceBus employs event-driven architectural principles to bake fault-tolerance and scalability into these processes.”

14

Page 15: Alt.Net Presentation

Added Blob storage And saga

15

DTC

is o

n!

Shohre Mansouri
Page 16: Alt.Net Presentation

Shipments have documentspublic class GetShipmentSagaData : IContainSagaData{

public virtual Guid Id { get; set; }public virtual Guid UpdatedShipmentCorrelationId { get; set; }public virtual string Originator { get; set; }public virtual string OriginalMessageId { get; set; }public virtual string ShipmentId { get; set; }

// The list of all documents that need to be uploaded:public virtual IList<DocumentKey> ShipmentDocumentKeys { get; set; }

// The documents that have been uploaded (successfully, or unsucessfully)public virtual IList<CompletedShipmentDocument> CompletedDocumentsOnSaga { get; set; }

public virtual ShipmentSagaData ShipmentData { get; set; }

}16

Page 17: Alt.Net Presentation

Keeping up-to-Date Vs InitialisingGetUpdatedShipmentsFromWcfCommand(version: 110, pageSize: 10)

GetUpdatedShipmentsFromWcfCommand(130, 10)

GetUpdatedShipmentsFromWcfCommand(146, 10)

GetUpdatedShipmentsFromWcfCommand(250, 10)

GetUpdatedShipmentsFromWcfCommand(295, 10)

GetUpdatedShipmentsFromWcfCommand(300, 10)

2 minutes later: GetUpdatedShipmentsFromWcfCommand(300, 10)

4 minutes later: GetUpdatedShipmentsFromWcfCommand(300, 10) 17

Page 18: Alt.Net Presentation

Keeping up-to-Date Vs Initialising

New -> Polling -> Complete and persist the next New

Version Polled Status Timestamp

100 Complete 4 minutes ago

112 Complete 2 minutes ago

112 New 1 second ago

18

Page 19: Alt.Net Presentation

Messages were lost!Azure service bus is not

Distributed transactional!

19

Page 20: Alt.Net Presentation

Stuck polling sessionsVersion Polled Status Timestamp

100 Complete Last night - 4 minutes

112 Complete Last night - 2 minutes

112 Polling Last night

20

Page 21: Alt.Net Presentation

OutBoxAdd another graph here!

21

Page 22: Alt.Net Presentation

NService Bus OutBoxNow we need an Outbox!

22

Page 23: Alt.Net Presentation

Code of outboxBusConfiguration busConfiguration = new BusConfiguration();

busConfiguration.EnableOutbox();

<appSettings> <add key="NServiceBus/Outbox" value="true" /></appSettings>

23

Page 24: Alt.Net Presentation

OutBox CaveatsBoth the business data and deduplication data need to share the same database.

So we moved NSB Saga to SQL server!

24

Page 25: Alt.Net Presentation

Finaly!

25

DTC

is o

ff!

Page 26: Alt.Net Presentation

Stuck polling sessionsThis time with messages in the error queue...

Version Polled Status Timestamp

100 Complete Last night - 4 minutes

112 Complete Last night - 2 minutes

112 Polling Last night

26

Page 27: Alt.Net Presentation

Got rid of statusVersion Polled Timestamp

100 4 minutes ago

112 2 minutes ago

112 Now - 1 second

27

Page 28: Alt.Net Presentation

We lost the battle but won the war

28

Page 29: Alt.Net Presentation

Only one thing is leftInitialising!

But I know it is going to be bloody easy.

29

Page 30: Alt.Net Presentation

Questions?

30