Enterprise Java Developer’s Survival Guide

A presentation at ISTA Con in November 2017 in Sofia, Bulgaria by Petyo Dimitrov

Slide 1

Slide 1

Enterprise Java Developer’s handbook Petyo Dimitrov 1 Survival guide

Slide 2

Slide 2

AGENDA Motivation Steps for survival Q&A 2 Survival guide

Slide 3

Slide 3

THE ENTERPRISE JAVA WILDERNESS 3 Survival guide

Slide 4

Slide 4

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

Slide 5

Slide 5

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 5 Survival guide

Slide 6

Slide 6

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 6 Survival guide

Slide 7

Slide 7

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

Slide 8

Slide 8

IDES & TOOLS 8 Survival guide

Slide 9

Slide 9

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

Slide 10

Slide 10

SPRING VS JAVA EE 10 Survival guide

Slide 11

Slide 11

CLIENT REQUIREMENTS 11 Survival guide

Slide 12

Slide 12

KNOWLEDGE REQUIREMENTS 12 Survival guide

Slide 13

Slide 13

PROJECT REQUIREMENTS 13 Survival guide

Slide 14

Slide 14

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

Slide 15

Slide 15

AND NOW WHAT? 15 Survival guide

Slide 16

Slide 16

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

Slide 17

Slide 17

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

Slide 18

Slide 18

BASIC SETUP (2) 18 Survival guide

Slide 19

Slide 19

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 19 Survival guide

Slide 20

Slide 20

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 20 Survival guide

Slide 21

Slide 21

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

Slide 22

Slide 22

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

Slide 23

Slide 23

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 23 Survival guide

Slide 24

Slide 24

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 24 Survival guide

Slide 25

Slide 25

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

Slide 26

Slide 26

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 26 Survival guide

Slide 27

Slide 27

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 27 Survival guide

Slide 28

Slide 28

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 28 Survival guide

Slide 29

Slide 29

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

Slide 30

Slide 30

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) 30 Survival guide

Slide 31

Slide 31

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 31 Survival guide

Slide 32

Slide 32

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 32 Survival guide

Slide 33

Slide 33

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

Slide 34

Slide 34

QUESTIONS? 34 Survival guide

Slide 35

Slide 35

THANK YOU petyo.dimitrov@gmail.com 35 Survival guide