A presentation at ISTA Con in in Sofia, Bulgaria by Petyo Dimitrov
Enterprise Java Developer’s handbook Petyo Dimitrov 1 Survival guide
AGENDA Motivation Steps for survival Q&A 2 Survival guide
THE ENTERPRISE JAVA WILDERNESS 3 Survival guide
STEP 1: COME PREPARED What do I need to know to be an Enterprise Java developer? 4 Survival guide
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
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
STEP 2: BRING GEAR What tools should I be experienced in? 7 Survival guide
IDES & TOOLS 8 Survival guide
STEP 3: GET ORIENTED Which technology stack should I choose? 9 Survival guide
SPRING VS JAVA EE 10 Survival guide
CLIENT REQUIREMENTS 11 Survival guide
KNOWLEDGE REQUIREMENTS 12 Survival guide
PROJECT REQUIREMENTS 13 Survival guide
POPULAR JAVA EE SPECIFICATIONS ZeroTurnaround’s survey of ~1700 developers 14 Survival guide
AND NOW WHAT? 15 Survival guide
STEP 4: BUILD SHELTER How do I setup the project? 16 Survival guide
BASIC SETUP (1) CI: Build: VCS: 17 Survival guide
BASIC SETUP (2) 18 Survival guide
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
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
STEP 5: FIND WATER How do I implement the project? 21 Survival guide
SHOULD I USE AN ORM? relational new nosql legacy object centric data centric CRUD queries reporting queries 22 Survival guide
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
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
HOW TO DESIGN REST API-S? (2) • Medium grained resources • up to two levels of nesting • Security: • HTTPS • OAuth2 • BasicAuth 25 Survival guide
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
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
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
STEP 6: FIND FOOD What about performance? 29 Survival guide
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
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
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
STEP 7: STAY IN ONE PLACE VS SCOUT THE AREA 33 Survival guide
QUESTIONS? 34 Survival guide
THANK YOU petyo.dimitrov@gmail.com 35 Survival guide