33degree krzysztof debski - let's build a solid base for a scale

68
@DebskiChris #33rdDegree Krzysztof Dębski Allegro Group Let’s build a solid base for a scale

Upload: krzysztof-debski

Post on 10-May-2015

564 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: 33degree Krzysztof Debski - Let's build a solid base for a scale

@DebskiChris

#33rdDegree

Krzysztof Dębski Allegro Group

Let’s build a solid base for a scale

Page 2: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Agenda

The Allegro Situation How to build a new World? The way to improve What’s in it for you?

Page 3: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

The Allegro Situation

Page 4: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Allegro

Page 5: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Allegro

6 million LOC

Page 6: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

400 people in IT

Allegro

Page 7: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

A New Hope

Page 8: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

A New Hope

Page 9: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

A New Hope

Page 10: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

A New Hope?

Service

Oriented

Ambiguity

Page 11: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Domain Driven Design

Page 12: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

(Micro)Services

Page 13: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Business needs

User

Transaction

Offer

Page 14: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Independent

User

Transaction

Offer

Page 15: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

API

User

Transaction

Offer

Page 16: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Polyglot

Cassandra

MongoDB

Oracle

User

Transaction

Offer

Page 17: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Smart Endpoints

Cassandra

MongoDB

Oracle

Offer

Transaction

User

Page 18: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

The first approach

Service

Auto deployable Auto monitored Auto scalable Auto healable Auto discoverable … and many more features

Page 19: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

How to build a new World?

Page 20: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

The first project

Service

Jetty Server

War file

Spring

Gradle

Page 21: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Let’s REST

JAX-RS / JSR Compliant @Path("/users") @Consumes(CONTENT_TYPE_JSON) @Produces(CONTENT_TYPE_JSON) public class UsersEndpoint {

// [...] @GET public UserCollectionResponse findAllUsers() { //[...] }

}

Page 22: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Let’s expose our methods

Swagger @Path("/users") @Api(value = "/users") @Consumes(CONTENT_TYPE_JSON) @Produces(CONTENT_TYPE_JSON) public class UsersEndpoint {

// [...] @ApiOperation(value=“Get all users”, response=UserCollectionResponse.class) @GET public UserCollectionResponse findAllUsers() { //[...] }

}

Page 23: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Let’s expose our methods

Swagger @Path("/users") @Api(value = "/users") @Consumes(CONTENT_TYPE_JSON) @Produces(CONTENT_TYPE_JSON) public class UsersEndpoint {

// [...] @ApiOperation(value=“Get all users”, response=UserCollectionResponse.class) @GET public UserCollectionResponse findAllUsers() { //[...] }

}

Page 24: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Let’s expose our methods

Swagger

Page 25: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper

Page 26: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper

Register

Page 27: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper

Page 28: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper

Get User

Page 29: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper

Get User

Page 30: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper

Get User Get offer for user

Page 31: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Multiple API versions

Content negotiation @Path("/users") @Consumes(”application/json”) @Produces(”application/json”) public class UsersEndpoint {

// [...] @GET public UserCollectionResponse findAllUsers() { //[...] }

}

Page 32: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Multiple API versions

Content negotiation @Path("/users") @Consumes(”application/vnd.allegro.user.v1+json”) @Produces(”application/vnd.allegro.user.v1+json”) public class UsersEndpoint {

// [...] @GET public UserCollectionResponse findAllUsers() { //[...] }

}

curl --dump-header - -H ”Accept: application/vnd.allegro.user.v1+json" -X GET http://localhost:8080/users

Page 33: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Multiple API versions

Content negotiation @Path("/users") @Consumes(”application/vnd.allegro.user.v1+json”) @Produces(”application/vnd.allegro.user.v1+json”) public class UsersEndpoint {

// [...] @GET @Produces(“application/vnd.allegro.user.v2+json”) public UserCollectionResponse findAllUsers() { //[...] }

}

curl --dump-header - -H ”Accept: application/vnd.allegro.user.v2+json" -X GET http://localhost:8080/users

Page 34: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

And it became slow…

Page 35: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Lower startup time

External Jetty

Service

Jetty Server

War file

Page 36: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Lower startup time

Embedded Jetty

Service

Jetty Server

Jar file

Page 37: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Lower startup time

Embedded Jetty

Service

Jetty Server

Jar file

Page 38: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Lower startup time

Embedded UnderTow

Service

Jetty Server Undertow

Jar file

Page 39: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Lower startup time

Immutable Images

Service

Undertow

Zip file

Server

Immutable image

Page 40: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

How to configure it?

Service

java –jar service.jar

Page 41: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

How to configure it?

Service ZooKeeper

java –jar service.jar –Dzookeeper.address=zookeper.service

Page 42: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

How to configure it?

Service ZooKeeper

java –jar service.jar –Dzookeeper.address=zookeper.service –Denvironment=prod

prod.properties

Page 43: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

How to configure it?

Service ZooKeeper

java –jar service.jar –Dzookeeper.address=zookeper.service –Denvironment=prod -Dservice.name=testService

prod.properties

Page 44: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

Tests

Page 45: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Do you test your tests?

Pitest

Page 46: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Integration tests

Test without mocks Run from IDE

public class UsersIntegrationTest {

private static Map<String, String> overrideConfiguration = Maps.newHashMap();

static { overrideConfiguration.put("property.name", "This was overwritten value"); }

@ClassRule public static final RestServiceStarted DEPLOYED_SERVICE = new RestServiceStarted(overrideConfiguration);

private WebTarget getUsersResourceWebTarget() { return DEPLOYED_SERVICE.getWebTarget().path("users"); }

}

Page 47: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

Monitoring

Page 48: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Let’s see what’s happening

NxLog LogStash Kibana

Page 49: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Let’s see what’s happening

Graphite # Metrics metrics.reporters.graphite.enabled=true metrics.reporters.graphite.host=graphite.service metrics.reporters.graphite.port=2003 metrics.reporters.graphite.prefix=stats.Prod.service metrics.reporters.interval=30

Page 50: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Monolith Alert

Page 51: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Monolith Alert

Multi module project support

Page 52: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Monolith Alert

Multi module project support

Page 53: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

The way to improve

Page 54: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Authentication

OAuth2

Page 55: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Patch Support

Standardized by IETF https://tools.ietf.org/html/rfc6902

PATCH /user/1 HTTP/1.1 Host: user.service.local Content-Length: 312

Content-Type: application/json-patch+json [

{”op”: ”test”, ”path”: ”/firstname”, ”value”: ”Jane”}, {”op”: ”add”, ”path”: ”/maidenname”, ”value”: ”Smith”}, {”op”: ”replace”, ”path”: ”/lastname”, ”value”: ”Doe”},

{”op”: ”remove", ”path”: ”/meetings”}, {”op”: ”move”, ”from”: ”/balance”, ”path”: ”sharedbalance”}, {”op”: ”copy”, ”from”: ”/a”, ”path”: ”/b”}

]

Page 56: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Simplify annotations

Swagger? @Path("/users") @Api(value = "/users") @Consumes(CONTENT_TYPE_JSON) @Produces(CONTENT_TYPE_JSON) public class UsersEndpoint {

// [...] @ApiOperation(value=“Get all users”, response=UserCollectionResponse.class) @GET public UserCollectionResponse findAllUsers() { //[...] }

}

Page 57: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Deployment

Docker support

Page 58: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

What’s in it for you?

Page 59: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Use the latest tools

GradleW in CI ENV and parent POM issues. Don’t do DDOS yourself and your partners.

Page 60: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Change is the only constant

Deployment tools Service API provider Dependency injection HTTP Server

Cargo Docker

Ecosystem

Swagger Jersey addon

Guice Spring

Jetty Undertow

Page 61: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Focus on right metrics

How to have 100% code coverage? public class UserMediaType {

public static final String V1_JSON = "application/vnd.allegro.user.v1+json” public static final String V2_JSON = "application/vnd.allegro.user.v2+json”

}

Page 62: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Focus on right metrics

import org.junit.Test; import static net.trajano… public class MediaTypesTest { @Test public void mediaTypesShouldBeValidUtilityClasses()

throws Throwable { assertUtilityClassWellDefined(UserMediaType.class); } }

You don’t need 100% code coverage!

Page 63: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Tools also lie

Metrics tend to lie

Configuration: default PHP metrics

Tested file: 4535 CLOC Imperative programming

Page 64: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Tools also lie

How many violations are there?

Page 65: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Tools also lie

How many violations are there?

4 At least according to Sonar.

Page 66: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Learn to REST

REST is not so obvious

/api/bi/XYZ123/1

/recommendations/1/items

/offer/100?output=ESI/JSON

Page 67: 33degree Krzysztof Debski - Let's build a solid base for a scale

#33rdDegree @DebskiChris Allegro The New World Improvement WIIFY

Community

Involve all developers in building the Bootstrap. Or they will build their own tools.

Łukasz Drumiński Mateusz Gajewski @wendigo

Page 68: 33degree Krzysztof Debski - Let's build a solid base for a scale

Allegro The New World Improvement WIIFY #33rdDegree @DebskiChris

Q & A