Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

WHAT YOU’LL LEARN Node.js or Dart Thinking in Dart Debugging Dart Deploying Dart @faisalabid +faisalabidx

Slide 3

Slide 3 text

ABOUT ME Entrepreneur & Engineer Deployed many large scale Node.js API’s Written a handful of Dart web projects for clients Working in healthcare @ LEAGUE, during the day @faisalabid +faisalabidx

Slide 4

Slide 4 text

THE BACKSTORY Market Wolf is a native Android application powered by a Dart API Originally was Node.js Utilizes RethinkDB WebSockets Medium sized API @faisalabid +faisalabidx

Slide 5

Slide 5 text

DIAGRAM OF ARCITECTURE IN NODE @faisalabid +faisalabidx MB Node Node Node

Slide 6

Slide 6 text

LIVE DEMO @faisalabid +faisalabidx

Slide 7

Slide 7 text

WHY SWITCH FROM NODE.JS TO DART? Tooling & debugging support for Node.js is a pain Already using Dart & Polymer for other front-end applications Written too many Node.js projects With that in mind, I began my investigation into Node.js and Dart @faisalabid +faisalabidx

Slide 8

Slide 8 text

NODE.JS & DART @faisalabid +faisalabidx

Slide 9

Slide 9 text

NODE.JS & DART - THE SIMILARITIES Both are great platforms TechEmpower.com/benchmarks/ - Both rate pretty good. Dart is slightly ahead Both are single threaded * and event based Both install and run with a very low memory footprint JIT compiled so they start up very fast and run great @faisalabid +faisalabidx

Slide 10

Slide 10 text

NODE.JS & DART - THE DIFFERENCES Different programming paradigm Node.js’s multiple vm’s compared to Dart’s isolates No “forever” tool to restart Dart servers when they crash. Though easy to build into your application @faisalabid +faisalabidx

Slide 11

Slide 11 text

PROS & CONS OF MOVING TO DART PRO: Better profiling and debugging in Dart PRO: Syntax and language features PRO: Organization of code is better and enforced PRO: Support for all major databases on pub.dartlang.org PRO/CON: Shift in thinking CON: Missing support for esoteric and very new database. But most protocols are JSON based so easy to port it @faisalabid +faisalabidx

Slide 12

Slide 12 text

NOW WHAT? Node.js API written in Express What’s the Express alternative in Dart? @faisalabid +faisalabidx

Slide 13

Slide 13 text

EXPRESS ALTERNATIVE IN DART Redstone Shelf by Google RPC by Google *There are others but these 3 are the gaining popularity* @faisalabid +faisalabidx

Slide 14

Slide 14 text

REDSTONE Actively developed by community Very “express-y” Good community support for middlewares/plugins PostgresSQL Mapper MongoDB Mapper Session Management Static HTML @faisalabid +faisalabidx

Slide 15

Slide 15 text

EXPRESS HELLO WORLD @faisalabid +faisalabidx

Slide 16

Slide 16 text

REDSTONE HELLO WORLD @faisalabid +faisalabidx

Slide 17

Slide 17 text

REDSTONE Dart example is more cleaner Easy to understand @faisalabid +faisalabidx

Slide 18

Slide 18 text

SHELF The base for Redstone Minimal no-frills component set to build a custom API framework Use middleware for routing Redstone’s middlewares come from Shelf. Both are the same Simple API @faisalabid +faisalabidx

Slide 19

Slide 19 text

EXPRESS HELLO WORLD @faisalabid +faisalabidx

Slide 20

Slide 20 text

SHELF HELLO WORLD @faisalabid +faisalabidx

Slide 21

Slide 21 text

SHELF Very minimal if you can get away with it Simple API, compared to Express Made by Dart team @faisalabid +faisalabidx

Slide 22

Slide 22 text

RPC The newest of the two Enables you to write RPC style Dart API’s easily Self documenting API Takes advantage of annotations @faisalabid +faisalabidx

Slide 23

Slide 23 text

EXPRESS HELLO WORLD @faisalabid +faisalabidx

Slide 24

Slide 24 text

RPC HELLO WORLD @faisalabid +faisalabidx

Slide 25

Slide 25 text

RPC HELLO WORLD @faisalabid +faisalabidx

Slide 26

Slide 26 text

RPC Bit more verbose Very clear API Bonus feature. Generate client side libraries in Java, Python and others Made by the Dart team We went with RPC @faisalabid +faisalabidx

Slide 27

Slide 27 text

WEBSOCKETS Market Wolf pushes data to clients in realtime using WebSockets Dart comes natively with WebSockets @faisalabid +faisalabidx

Slide 28

Slide 28 text

WEBSOCKET EXAMPLE @faisalabid +faisalabidx

Slide 29

Slide 29 text

BUILDING BLOCKS Now all the building blocks were ready Dart comes natively with WebSockets @faisalabid +faisalabidx

Slide 30

Slide 30 text

THINKING IN DART @faisalabid +faisalabidx

Slide 31

Slide 31 text

DIAGRAM OF ARCITECTURE IN NODE @faisalabid +faisalabidx MB Node Node Node

Slide 32

Slide 32 text

DART ARCHITECTURE Easy to replicate Node.js, but we must think in Dart Simplify the architecture by using isolates @faisalabid +faisalabidx

Slide 33

Slide 33 text

ISOLATES Every Dart application runs in an isolate Isolate is an independent worker that runs in its own memory heap Spawn multiple isolate in a VM. Take advantage of multiple cores Isolates communicate to the main isolate via a send and receive port @faisalabid +faisalabidx

Slide 34

Slide 34 text

ISOLATE EXAMPLE @faisalabid +faisalabidx

Slide 35

Slide 35 text

ISOLATES Every Dart application runs in an isolate API to spawn multiple isolates in a VM. Take advantage of multiple cores Isolates communicate to the main isolate via a send and receive port This fit perfectly with our design @faisalabid +faisalabidx

Slide 36

Slide 36 text

DIAGRAM OF ARCHITECTURE IN NODE @faisalabid +faisalabidx MB Node Node Node

Slide 37

Slide 37 text

DIAGRAM OF ARCHITECTURE IN DART @faisalabid +faisalabidx API Stock Fetcher Leader board MAIN

Slide 38

Slide 38 text

THINKING IN DART Isolates are game changers when you develop Imagine spawning isolate to do database operations which don’t need to be returned to the user @faisalabid +faisalabidx

Slide 39

Slide 39 text

DEBUGGING DART @faisalabid +faisalabidx

Slide 40

Slide 40 text

MARKET WOLF OBSERVATORY ISOLATES @faisalabid +faisalabidx

Slide 41

Slide 41 text

MARKET WOLF OBSERVATORY HEAP @faisalabid +faisalabidx

Slide 42

Slide 42 text

DEBUGGING IN DART Debugging & Profiling applications is very simple using Observatory This alone justifies moving to Dart among all other things @faisalabid +faisalabidx

Slide 43

Slide 43 text

DEPLOYING DART TO THE SERVER @faisalabid +faisalabidx

Slide 44

Slide 44 text

DEPLOYING TO SERVER Node.js application used AWS Beanstalk to deploy application Beanstalk lets you deploy your application with a simple terminal command. Amazon handles all the scaling, load balancing and deployment for you Does not explicitly provide support for Dart But implicitly it does @faisalabid +faisalabidx

Slide 45

Slide 45 text

RUNNING DART ON AWS BEANSTALK Beanstalk lets you deploy Docker images Docker is a very very lightweight virtual machine that you can configure in the form of a Dockerfile The Dockerfile describes what will go in your Docker runtime Beanstalk will deploy that image Luckily for us. Google has a base Dart VM Docker image ready for us @faisalabid +faisalabidx

Slide 46

Slide 46 text

DOCKERFILE EXAMPLE @faisalabid +faisalabidx

Slide 47

Slide 47 text

RUNNING DART ON AWS BEANSTALK Now that we have our Dockerfile ready we need to tell Beanstalk about it @faisalabid +faisalabidx

Slide 48

Slide 48 text

DOCKERFILE.AWS.JSON @faisalabid +faisalabidx

Slide 49

Slide 49 text

RUNNING DART ON AWS BEANSTALK Now that we have our Dockerfile ready we need to tell Beanstalk about it Once you have that, all that you need to do is run the Elastic Beanstalk deployment command @faisalabid +faisalabidx eb deploy

Slide 50

Slide 50 text

WAS IT WORTH IT? @faisalabid +faisalabidx

Slide 51

Slide 51 text

WAS IT WORTH IT? Yes. No question about it Dart’s syntax. Language features. Isolates. Observatory all make a strong compelling case to move to Dart Do we find anything missing now that we are moved away from Node.js? Not at all # lines of code shrunk dramatically. Easier to debug, deploy, less dependencies to worry about @faisalabid +faisalabidx

Slide 52

Slide 52 text

MOVING FROM NODE.JS TO DART WAS THE BEST DECISION WE MADE @faisalabid +faisalabidx FOR US, ALL API PROJECTS MOVING FORWARD, WILL BE WRITTEN IN DART

Slide 53

Slide 53 text

THANK YOU @faisalabid +faisalabidx [email protected] @FAISALABID