Enterprise Java Developer’s Survival Guide

A presentation at Muffin Conference Belgrade in March 2017 in Belgrade, Serbia by Petyo Dimitrov

Slide 1

Slide 1

Enterprise Java Developer’s handbook Petyo Dimitrov

Slide 2

Slide 2

AGENDA Motivation Steps for survival Q&A 2 Survival guide

Slide 3

Slide 3

MOTIVATION 3 Survival guide

Slide 4

Slide 4

THE ENTERPRISE JAVA WILDERNESS 4 Survival guide

Slide 5

Slide 5

STEP 1: COME PREPARED What do I need to know to be an Enterprise Java developer? 5 Survival guide

Slide 6

Slide 6

KNOWLEDGE (1) Solid understanding of core Java & some specifics: • garbage collection strategies • class loading specifics • debugging (thread & heap dumps) Some experience with databases and middleware 6 Survival guide

Slide 7

Slide 7

KNOWLEDGE (2) Knowledge in OOP concepts and design patterns • Singleton, Dependency Injection, Factory, MVC … Core Java EE specs like Servlets, JPA & Components Basic Linux command line skills 7 Survival guide

Slide 8

Slide 8

STEP 2: BRING GEAR What tools should I be experienced in? 8 Survival guide

Slide 9

Slide 9

IDES & TOOLS 9 Survival guide

Slide 10

Slide 10

STEP 3: GET ORIENTED Which technology stack should I choose? 10 Survival guide

Slide 11

Slide 11

SPRING VS JAVA EE 11 Survival guide

Slide 12

Slide 12

CLIENT REQUIREMENTS 12 Survival guide

Slide 13

Slide 13

KNOWLEDGE REQUIREMENTS 13 Survival guide

Slide 14

Slide 14

PROJECT REQUIREMENTS 14 Survival guide

Slide 15

Slide 15

POPULAR JAVA EE SPECIFICATIONS ZeroTurnaround’s survey of ~1700 developers 15 Survival guide

Slide 16

Slide 16

AND NOW WHAT? 16 Survival guide

Slide 17

Slide 17

STEP 4: BUILD SHELTER How do I setup the project? 17 Survival guide

Slide 18

Slide 18

BASIC SETUP (1) CI: Build: VCS: 18 Survival guide

Slide 19

Slide 19

BASIC SETUP (2) 19 Survival guide

Slide 20

Slide 20

ADVANCED SETUP 1. 2. 3. 4. 5. 6. Static code analysis  Sonar / IDE-based DB schema management  Flyway / Liquibase In-memory DB for development Easy to setup local environment Stable staging environment Continuous Delivery 20 Survival guide

Slide 21

Slide 21

UNIT TESTING! Via JUnit & Mockito / Groovy & Spock Caveats: • one-off short-term projects • tests treated as second class code • meaningless tests • brittle tests (white box, extensive mocking) • lack of strategy for test data 21 Survival guide

Slide 22

Slide 22

STEP 5: FIND WATER How do I implement the project? 22 Survival guide

Slide 23

Slide 23

SHOULD I USE AN ORM? relational new nosql legacy object centric data centric CRUD queries reporting queries 23 Survival guide

Slide 24

Slide 24

WHAT PROBLEMS CAN I EXPECT? “Magic” powers i.e. hidden learning curve Reduced control over DB Loss of DB specific capabilities Difficulty fetching necessary data Performance issues and locks 24 Survival guide

Slide 25

Slide 25

HOW TO DESIGN REST API-S? • Follow the REST principles & look at the APIs of large companies • Use proper HTTP verbs (GET, PUT, POST, …) • GET /movie/1/booking • Use proper HTTP status codes • 418 I‘m a teapot 25 Survival guide

Slide 26

Slide 26

HOW TO DESIGN REST API-S? (2) • Medium grained resources • up to two levels of nesting • Security: • HTTPS • OAuth2 • BasicAuth 26 Survival guide

Slide 27

Slide 27

HOW TO DESIGN REST API-S? (3) • Proper URLs using plural nouns • GET /movies vs GET /getAllMovies • Spinal-case in URLs and camelCase / snake_case for parameters • http://www.penisland.net/ • GET /order-item/1?orderNumber=2 27 Survival guide

Slide 28

Slide 28

HOW TO DESIGN REST API-S? (4) • Consider versioning early on: • only major version • aim to have up to 2 versions in parallel • /v1/movies, /v2/movies • Filters & sorting via URL parameters • ?sort=rating,budget&director=nolan 28 Survival guide

Slide 29

Slide 29

HOW TO DESIGN REST API-S? (5) • I18n of data: • via Accept-Language: bg_BG • Handling of operations (i.e. non-resources) • POST /email/12/send • consider JSON-RPC 29 Survival guide

Slide 30

Slide 30

STEP 6: FIND FOOD What about performance? 30 Survival guide

Slide 31

Slide 31

WHAT PROBLEMS SHOULD I EXPECT? • Infrastructure issues (available resources, unreliability, latency) • External system communication (synchronous calls, no timeouts, faulty integrations) • Lack of middleware tuning (thread & connection pools, clusters) • Garbage collection (limits, strategies) • Bugs (synchronization issues, memory leaks) 31 Survival guide

Slide 32

Slide 32

HOW TO IMPROVE PERSISTENCE? 1. Monitor query performance 2. Review native SQL of sensitive queries • mark/optimize slow queries 3. Use caching offered by ORM 4. Beware of many‐to‐many relations & fetch types 5. Run updates/deletes in bulk (beware of cascading) 6. Paging & query projection 7. Move logic to DB 32 Survival guide

Slide 33

Slide 33

HOW TO IMPROVE FRONT END? 1. Track time for processing each REST request 2. Use gzip 3. Partial request & responses (?fields + HTTP PATCH) 4. Cache friendly results (etag, last‐modified) 5. Paging 33 Survival guide

Slide 34

Slide 34

STEP 7: STAY IN ONE PLACE VS SCOUT THE AREA 34 Survival guide

Slide 35

Slide 35

QUESTIONS? 35 Survival guide

Slide 36

Slide 36

THANK YOU petyo.dimitrov@musala.com 36 Survival guide