JavaOne 2016 -Emerging Web App Architectures using Java and node.js

87
Emerging Web App Architectures Using Java and Node.js

Transcript of JavaOne 2016 -Emerging Web App Architectures using Java and node.js

Emerging Web App ArchitecturesUsing Java and Node.js

2

@stevewallin

Steve Wallin

JCP EC memberProgram Director, IBM

3

Learning to code as a product of the 80’s

4

Learning to code as a product of the 80’s

5

Learning to code as a product of the 80’s

6

Learning to code as a product of the 80’s

7

Learning to code as a product of the 80’s

8

Learning to code as a product of the 80’s / 90’s

9

Learning to code as a product of the 80’s / 90’s

10

3-Tier Web Applications

11

3-Tier Web Applications

HTTP

12

3-Tier Web Applications

HTTP

Load

Bal

ance

r

13

3-Tier Web Applications

HTTP

Load

Bal

ance

r

14

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

3-Tier Web Applications

15

Java and JEE based Web Applications

16

From Web Sites to Web Apps

● JavaScript is ubiquitous in the browser- Supported in every browser- Integration with HTML and CSS

● JavaScript is not affected by negative publicity....

17

Unless it is absolutely necessary to run Java in web browsers, disable it as described below, even after updating to 7u11. This will help mitigate other Java vulnerabilities that may be discovered in the future.

This and previous Java vulnerabilities have been widely targeted by attackers, and new Java vulnerabilities are likely to be discovered. To defend against this and futureJava vulnerabilities, consider disabling Java in web browsers…

Programming in the Browser

18

FullStack JavaScript Development

● Reuse of programming skills and teams● Reuse of skills for both client and server side code

● Reuse of “isomorphic” code components● Reuse of code for both client and server● Write One Run Anywhere

● Faster user experience performance● Use of server side rendering

19

Fashion and trends

20

+

Node.js and Java

21

Language selection

22

Language selection

23

API Package Support

● Node.js:● 300K+ packages● 430 packages/day

● Java growth:● 150K packages● 100 packages/day

24

● Average 45% less code required for Node.js implementation

Code required to implement benchmarks

25

var cluster = require('cluster');var cpus = require('os').cpus().length;var http = require('http');

if (cluster.isMaster) {for (var i = 0; i < cpus; i++) {

cluster.fork();}cluster.on('death', function(worker) {

console.log("Worker" + worker.pid + "died");});

} else {http.createServer(function(request, response) {

response.writeHead(200, {"Content-Type": "text/plain"});response.write("Hello World!\n");response.end();

}).listen(8080);}

Writing a HTTP Server

26

var cluster = require('cluster');var cpus = require('os').cpus().length;var http = require('http');

if (cluster.isMaster) {for (var i = 0; i < cpus; i++) {

cluster.fork();}cluster.on('death', function(worker) {

console.log("Worker" + worker.pid + "died");});

} else {http.createServer(function(request, response) {

response.writeHead(200, {"Content-Type": "text/plain"});response.write("Hello World!\n");response.end();

}).listen(8080);}

And Clustering It….

27

● One thread (or process) per connection- Each thread waits on a response- Scalability determined by the number of

threads

● Each thread:- consumes memory- is relatively idle

● Concurrency determined by number of depot workers

Typical Java Approach to Scalable I/O

28

● One thread multiplexes for multiple requests- No waiting for a response- Handles return from I/O when notified

● Scalability determined by:- CPU usage- “Back end” responsiveness

● Concurrency determined by how fast the food server can work

Node.js approach to Scalable I/O

29

Algorithmic Performance

30

Algorithmic Performance

31

Web App Performance

MoreComputation

MoreI/O

32

Web App Performance

MoreComputation

MoreI/O

33

Web App Performance

MoreComputation

MoreI/O

34

Web App Performance

MoreComputation

MoreI/O

35

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){int a = 5;int b = 3;

add(a, b);}

> javac app.java> java app

> 8

var add = function (a, b) {console.log(a + b);

}

var a = 5;var b = 3;

add(a, b);

> node app.js

> 8

36

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){int a = 5;int b = 3;

add(a, b);}

> javac app.java> java app

> 8

var add = function (a, b) {console.log(a + b);

}

var a = 5;var b = 3;

add(a, b);

> node app.js

> 8

37

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){int a = 5;int b = 3;

add(a, b);}

> javac app.java> java app

> 8

var add = function (a, b) {console.log(a + b);

}

var a = 5;var b = 3;

add(a, b);

> node app.js

> 8

38

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){int a = 5;int b = 3;

add(a, b);}

> javac app.java> java app

> 8

var add = function (a, b) {console.log(a + b);

}

var a = 5;var b = 3;

add(a, b);

> node app.js

> 8

39

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){int a = 5;int b = 3;

add(a, b);}

> javac app.java> java app

> 8

var add = function (a, b) {console.log(a + b);

}

var a = 5;var b = 3;

add(a, b);

> node app.js

> 8

40

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){String a = new String(“5”);int b = 3;

add(a, b);}

> javac app.java> java app

> 8

var add = function (a, b) {console.log(a + b);

}

var a = ‘5’;var b = 3;

add(a, b);

> node app.js

> 8

41

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){String a = new String(“5”);int b = 3;

add(a, b);}

> javac app.java> java app

> 8

var add = function (a, b) {console.log(a + b);

}

var a = ‘5’;var b = 3;

add(a, b);

> node app.js

> 8

42

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){String a = new String(“5”);int b = 3;

add(a, b);}

> javac app.javaError: incompatible types: String cannot be converted to int

add(a, b);^

var add = function (a, b) {console.log(a + b);

}

var a = ‘5’;var b = 3;

add(a, b);

> node app.js

> 8

43

Simple Calculation: 5 + 3

private static void add (int a, int b){System.out.println(a + b);

}

public static void main(String[] args){String a = new String(“5”);int b = 3;

add(a, b);}

> javac app.javaError: incompatible types: String cannot be converted to int

add(a, b);^

var add = function (a, b) {console.log(a + b);

}

var a = ‘5’;var b = 3;

add(a, b);

> node app.js

> 53

44

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // Weak typing, implicit conversion

> '5' – '4'1 // String minus String = Integer??

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

45

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // Weak typing, implicit conversion

> '5' – '4'1 // String minus String = Integer??

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

46

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // String minus String = Integer??

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

47

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // String minus String = Integer??

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

48

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // Both Strings converted to number for subtraction

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

49

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // Both Strings converted to number for subtraction

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

50

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // Both Strings converted to number for subtraction

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

51

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // Both Strings converted to number for subtraction

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

52

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // Both Strings converted to number for subtraction

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

53

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // Both Strings converted to number for subtraction

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // ...but that isn't

54

JavaScript Calculations

> 5 + 38

> '5' + 3'53'

> '5' – 32 // String is converted to a number for subtraction

> '5' – '4'1 // Both Strings converted to number for subtraction

> '5' + + '4'54 // Multiple +'s are ok

> 'Hello' + 'World''HelloWorld' // Ok, that's expected

> 'Hello' + + 'World''HelloNaN' // Multiple plus must cause String to number conversion

55

JavaScript Calculations

> '5' + - '2''5-2' // I can just about see that works

> var x = 3undefined> '5' – x + x5 // Ok, that makes sense

> var x = 3undefined> '5' + x - x50 // What???

56

JavaScript Calculations

> '5' + - '2''5-2' // I can just about see that works

> var x = 3> '5' – x + x5 // Ok, that makes sense

> var x = 3undefined> '5' + x - x50 // What???

57

JavaScript Calculations

> '5' + - '2''5-2' // I can just about see that works

> var x = 3> '5' – x + x5 // Ok, that makes sense

> var x = 3> '5' + x - x50 // What???

58

LanguageSelection

59

Choosing the Right Language for the Service

60

Choosing the Right Language for the Service

61

Node.js

0

- 4x

+ 1/3x

Node

.js P

erfo

rman

ce R

elat

ive

to J

ava

CPU Bound I/O Bound

* based on TechEmpower benchmark results

Application Performance(higher is better)

Choosing the Right Language for the Service

62

Node.js

0

- 4x

+ 1/3x

Node

.js P

erfo

rman

ce R

elat

ive

to J

ava

CPU Bound I/O Bound

* based on TechEmpower benchmark results

Application Performance(higher is better)

Choosing the Right Language for the Service

Error: incompatible typesClassCastException

63

Monolithic and Micro Services

Services are small and targeted to their taskServices are organized around capabilities

Services are self contained, storing their own data

“Do one thing, and do it well”

64

● Higher performance for I/O● Easier async programming● Fullstack/isomorphic development

Choosing the Right Language for the Service

65

Choosing the Right Language for the Service

● Higher processing performance● Type safety for calculations● Transaction processing frameworks

66

● Highly performant, scalable rich web applications● Highly performant, reliable transaction processing● Self-contained micro-service components

Choosing the Right Language for the Service

+

67

EmergingArchitectures

68

Forrester 4-Tier Applications

69

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

3-Tier Web Applications

70

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

Rich Web Applications

71

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

Rich Web Applications

72

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

Rich Web Applications

Load

Bal

ance

r

73

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Load

Bal

ance

r

74

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Load

Bal

ance

r

75

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Load

Bal

ance

r

76

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Load

Bal

ance

r

77

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

78

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

79

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Services

80

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Services

81

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Services

82

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Services

83

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Services

Client

84

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Services

Client

Delivery

85

Operations and Management

Admin Analytics

Load

Bal

ance

r

HTTP

MicroServices and API Economy

Client

DeliveryAggregation

Services

86

Node.js and Java

+

Get a Java Dockercontainer today !hub.docker.com

ibmjava

@stevewallin

Come and see us at the booth

nodereportappmetrics