ocassionally connected devices spark final

98
Occasionally Connected Devices Chris Ballance Diligent @ballance

Upload: chris-ballance

Post on 28-Jul-2015

71 views

Category:

Education


0 download

TRANSCRIPT

1. Occasionally Connected Devices Chris Ballance Diligent @ballance 2. What well cover Synchronization - Offline First! CAP Theorem Mobile Security Responsive Design & Engineering Case Studies Testing / Tools 3. Photo by Chris Ballance 4. Places where Ive built things 5. Test Man Test Man, 2002, reproduced under fair use 6. Common Fallacies Networks are reliable Data must always be 100% consistent between nodes CRUD can handle that (not very well) 7. Back to the Future, reproduced under fair use 8. Mobile First + Offline First 9. Designing Offline First Web Apps Alex Feyerke, 2013 http://alistapart.com/article/offline-first 10. Offline is not a feature 11. Design for Offline Add Sync as a feature 12. Your users will thank you 13. Development Considerations Idempotence Immutability Event Sourcing Local Caching Queueing 14. Immutability 15. Idempotency 16. Event Sourcing Append only All actions on nodes are stored Actions can be replayed to any point in history Current state is original + sum of all changes Addresses inherent limitations of CRUD Soft deletes only 17. CQRS Command Query Responsibility Segregation Able to scale read and write separately Separation between read / write code Safety - Queries are guaranteed to be free of side effects Better allows for specialization on the read side using caching models such as CDNs 18. Project Delivery Triangle Good Fast Cheap 19. Project Delivery Triangle Good Fast Cheap 20. CAP Theorem Consistent Available Partition Tolerant 21. CAP Theorem Consistent Available Partition Tolerant 22. Available Partition Tolerant Consistent 23. Consistent Partition TolerantAvailable 24. Consistent Available Partition Tolerant 25. Consistent Available Partition Tolerant Partition Tolerance is a myth! 26. We can guarantee Consistency, but not Availability. We may time out or fail to return anything Consistent Available Partition Tolerant 27. We can guarantee Availability, but our data may not be Consistent with other nodes Consistent Available Partition Tolerant 28. Our business needs will drive whether we choose Consistency or Availability Available Partition Tolerant Consistent 29. Implementations Consistent Available Partition TolerantAP Cassandra, CouchDB CP MongoDB, Big Table (GFS) CA RDBMS SQL Server 30. A contrived example for Consistency A B 31. User writes S1 to Node B A B S0 S0 S1 32. User queries Node A Nodes B & A have not syncd A B S1S0 33. Query is blocked until B syncs with A A B S0 S1 ? 34. Once B syncs with A, the query on A is unblocked and returns S1 as expected A B S1 S1S1 S1 :-) * The query could potentially time out 35. A contrived example for Availability A B 36. User writes S1 to Node B A B S1 S0 S0 37. User queries Node A for S1 A B S1S0 38. Query returns current state of A, but is not consistent with B A B S1 S0 S0 S1 ? 39. A later query of A yields S1 previously written to B. Eventual consistency has been achieved. A B S1 S1 S1 S1 :-) 40. Which of these are Idempotent? Console.WriteLine(person.FirstName); person.FirstName = Chris person.OrderBeer(); person.TakeOffShoes(); 41. Effective & Unobtrusive Get Smart, 1970, reproduced under fair use 42. Security Device security Data at rest Data in transit Data in memory Remote wipe 43. Data in Transit 44. Data at Rest 45. Security Walkthrough 46. Device Generates Asymmetric Key Pair 47. Device sends public key to server 48. 404! WTFBBQ? 49. Testing Considerations Network Latency Data - loss in transit Data - order of arrival Device simulation 50. Testing Tools DummyNet (Windows, etc) Network Link Conditioner (OSX) [demo] SoftPerfect (free for 30 second sessions) Charles (Windows) Android Simulator 51. Be Responsive! Responsive UX Responsive Engineering 52. Android Devices source: http://opensignal.com/reports/2014/android-fragmentation/ 53. Android OS source: http://opensignal.com/reports/2014/android-fragmentation/ 54. Facebook Lite source: http://www.wired.com/2015/06/facebook-launches-facebook-lite-super-slow-connections/ 55. Case Studies 56. My Public Github )-: 57. My Work GitHub (-: 58. A Gift Card System https://www.flickr.com/photos/68751915@N05/6710868859 59. Gift Card System The business values availability over consistency to a certain tolerance ($100) Eventual consistency is preferred to timeouts or failures Low chance of double-spend if this is a brick & mortar store 60. SpaceBook https://www.flickr.com/photos/nasahqphoto/8116469859/ 61. Social Media for Astronauts Network Latency to Low Earth Orbit is high May have network outages depending on position in orbit Dropped Packets P2P for app use when disconnected from Earth Photo by NASA 62. Financial Markets https://www.flickr.com/photos/laughingsquid/14313066998/ 63. Considerations for Financial Markets Consistency is more important than Availability Multiple markets (node partitions) Ultra-low Network latency is crucial Front-running orders* 64. Cryptocurrency Blockchains https://www.flickr.com/photos/laughingsquid/14313066998/ 65. RunKeeper 66. Occasionally Connected Devices are different Must work when disconnected Device and its data are vulnerable at rest Often connect over unsecured networks WIFI and cellular networks can be unreliable Other differences? 67. Further Reading Designing Offline-First web apps http://alistapart.com/article/offline-first CQRS - Martin Fowler Blog Post Amazon Dynamo - http://www.eurecom.fr/~michiard/teaching/slides/clouds /cap-dynamo.pdf Facebook Lite - http://www.wired.com/2015/06/facebook-launches- facebook-lite-super-slow-connections/ 68. What we covered Synchronization - Offline First! CAP Theorem Mobile Security Responsive Design & Engineering Case Studies Testing / Tools 69. Questions?