Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Offline Apps with Angular WebAPI and SQL Server

Thorsten Hans
September 28, 2017

Offline Apps with Angular WebAPI and SQL Server

Slides from my talk at BASTACon on building Apps with offline capabilities using Angular, WebAPI and SQL

Thorsten Hans

September 28, 2017
Tweet

More Decks by Thorsten Hans

Other Decks in Technology

Transcript

  1. Offline Apps Angular, WebAPI and SQL Server Thorsten Hans @thorstenhans

    [email protected] thorsten-hans.com @thinktecture [email protected] thinktecture.com Consultant @thinktecture
  2. Special Day “Cross-Plattform HTML5” Thema Sprecher Datum, Uhrzeit Raum Anfassen

    erlaubt: Mobile Apps mit Angular und Cordova Thomas Hilzendegen DO, 28. September 2017, 09.00 bis 10.00 Gutenberg-Saal 4 Fenster überall: Desktopanwendungen mit Angular und Electron Fabian Gosebrink DO, 28. September 2017, 10.45 bis 11.45 Gutenberg-Saal 4 Offline First mit Angular und SQL Server – Es geht auch ohne Netz Thorsten Hans DO, 28. September 2017, 12.00 bis 13.00 Gutenberg-Saal 4 Von Windows Forms und WPF in die neue HTML5-Welt Sebastian Gingter DO, 28. September 2017, 15.45 bis 16.45 Gutenberg-Saal 4 Web goes Native: Progressive Web Apps (PWA) – with Angular Shmuela Jacobs DO, 28. September 2017, 17.00 bis 18.00 Gutenberg-Saal 4
  3. What to expect • Definition of Offline • Architecture •

    Reference Implementation What not to expect • Angular Introduction • SQL Server deep dive
  4. What should “offline” mean to you, as a consumer? •

    Work without network • Data is always available • Interactions are executed once connected again Introduction to offline scenarios
  5. What does “offline” mean to you, as a dev? •

    Manually solve conflicts when syncing • Implement concurrency • Makes the App more complicated Introduction to offline scenarios
  6. When are your app consumers really offline? • Inside of

    complex buildings • Within many geographical areas • train, countryside • when network issues occur Introduction to offline scenarios
  7. When are your app consumers really offline? • It depends

    on the scenario • if a lot of data is being transferred … • Edge or 3G means offline • LTE with bad quality means offline • Apps are offline if your API is offline or not reachable Introduction to offline scenarios
  8. • Primary-Keys must be GUIDs (SQL uniqueidentifier) • Tables need

    row versions (SQL rowversion) • Triggers are required to mark related tables as modified Challenges at database tier
  9. • It’s a readonly column on a table • It’s

    automatically incremented by SQL Server • It’s scoped on the database level • It may exist only once on a table • It’s internally a binary(8) field à think of uint64 (shown as timestamp) RowVersion
  10. • GamesCategories is only synced indirectly • Triggers mark related

    entities as modified • Enforce a new RowVersion SQL Triggers
  11. • Provide changed data since last GET request (for bigger

    amounts of data) • Deal with bulk requests (connection has been recovered) • Add / Update / Delete Items • Deal with conflicts • Write data to database using local transactions Challenges at API tier
  12. • Store data locally • sensitive data à deploy as

    a native app using Electron / Cordova • Switch form HTTP calls to offline data storage immediately • Identify a proper connection state • No binary online/offline checks • Connection Restored Events • Provide conflict resolution UX / UI Challenges at SPA tier
  13. • SQLite (cordova or electron) • SQLiteCypher (cordova or electron)

    • IndexedDB • LocalStorage • SessionStorage Local Data Storages for HTML apps
  14. Tips from offline implementations we did • Design offline first

    • Implement adaptive UI and remove Actions which rely on network • Implement proper connectivity checks • Define concurrency • Implement conflict resolution • Trace / Log / Audit everything • Don’t underestimate implementation and specification efforts From the field
  15. • Real definition of offline • Impact on application architectures

    • Implementation for connectivity checks • Actual sync implementation is no magic • Can and will be time-consuming • Some tips from the field Recap