Transcript
Page 1: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

@DebskiChris

#AtmosphereConf

Krzysztof Dębski Allegro Group

Let’s build a solid base for a scale

Page 2: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

The Allegro Situation

Page 4: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Allegro

Page 5: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Allegro

6 million LOC

Page 6: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

400 developers

Allegro

Page 7: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

A New Hope

Page 8: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

A New Hope

Page 9: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

A New Hope

Page 10: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

A New Hope?

Service

Oriented

Ambiguity

Page 11: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Domain Driven Design

Page 12: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

(Micro)Services

Page 13: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Business needs Offer

User

Transaction

Page 14: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Offer

User

Transaction

Independent

Page 15: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

API Offer

User

Transaction

Page 16: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Polyglot

Cassandra

MongoDB

Oracle

Offer

User

Transaction

Page 17: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

(Micro)Services

Smart Endpoints

Cassandra

MongoDB

Oracle

Offer

User

Transaction

Page 18: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

The first approach

Service

Auto deployable Monitored Auto scalable Auto healable Auto discoverable

Page 19: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

How to build a new World?

Page 20: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

The first project

Gradle Spring External Jetty server

Page 21: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Let’s expose our methods

Swagger

Page 24: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper  

Register  

Page 25: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper  

Get  User  

Page 26: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper  

Get  User  

Page 27: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

And make them discoverable

Offer

User

Discovery ZooKeeper  

Get  User  Get  off

er  for  user  

Page 28: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Multiple API versions

Header support 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”

}

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

Page 29: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Multiple API versions

Content negotiation @Path("/users") @Consumes(AllegroUserMediaType.V1_JSON) @Produces(AllegroUserMediaType.V1_JSON) public class UsersEndpoint {

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

}

Page 30: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

How to configure it?

Page 31: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

How to configure it?

Zookeper Environment properties Command-line options

Page 32: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

And it became slow

Page 33: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Lower startup time

External Jetty Embedded Jetty Embedded UnderTow

Page 34: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Easier deployment

Cargo deployment Built to zip package On immutable images

Page 35: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

Tests

Page 36: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Do you test your tests?

Pitest

Page 37: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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 38: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

Monitoring

Page 39: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Let’s see what happens

LogStash Kibana NxLog

Page 40: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Let’s see what happens

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 41: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

Monolith Alert

Page 42: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Monolith Alert

Multi module project support

Page 43: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

The way to improve

Page 44: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Authentication

OAuth2

Page 45: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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 46: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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 47: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Deployment

Docker support

Page 48: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

What’s in it for you?

Page 49: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Use the latest tools

GradleW issue in Continuous Integration Environment and parent POM issues. Don’t do DDOS yourself and your partners’ sites.

Page 50: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Change is the only constant

HTTP Server Service API provider Dependency injection engine Deployment tools

Page 51: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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); } }

Page 52: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Tools also lie

Metrics tend to lie – Default PHP metrics in SonarQube – Tested file

•  4535 CLOC •  Whole code written using imperative programming

How many violations are there?

Page 53: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @DebskiChris Allegro The New World Improvement WIIFY

Tools also lie

How many violations are there?

4 At least according to Sonar

Page 54: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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 55: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

#AtmosphereConf @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 56: Atmosphere 2014: Let's build a solid base for a scale. - Krzysztof Debski

Allegro The New World Improvement WIIFY #AtmosphereConf @DebskiChris

Q & A


Top Related