javaone 2017 - choosing a nosql api and database to avoid tombstones and dragons in game on!...

33
GameOn! + JNoSQL #JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! Leonardo Lima Otávio Santana Kate Stanley

Upload: leonardo-de-moura-rocha-lima

Post on 21-Jan-2018

233 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Choosing a NoSQL API and Database to Avoid Tombstones and Dragons

in Game On!

Leonardo Lima Otávio SantanaKate Stanley

Page 2: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

About the Speakers

Katherine (Kate) Stanley

• Software Engineer, works for IBM

• From United Kingdom

• Work on Java development for IBM Cloud

• Committer to Game On

• Contributed to MicroProfile conference app

• Co-wrote IBM Redbook about Microservices with Java

Page 3: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

About the Speakers

Leonardo Lima

• Computer engineer, server & embedded sw developer

• From São Paulo, Brasil, currently in Austin, TX

• CTO at V2COM

• Spec Lead – JSR363 – Units of Measurement

• V2COM’s Representative at JCP Executive Committee

[about.me/leomrlima]

Page 4: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Otávio Santana

• Software engineer, Tomitribe

• From Salvador, Brazil

• Java Champion, SouJava JUG Leader

• Apache, Eclipse and OpenJDK Committer

• Expert Group member in many JSRs

• Representative at JCP EC for SouJava

About the Speakers

Page 5: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Microservices & GameOn!

Page 6: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Microservices are used to…

� … compose a complex application using:◦ “small”

◦ independent (autonomous)

◦ replaceable

◦ processes

� … that communicate via language-agnostic APIs

Microservice

MicroserviceMicroservice

Microservice

Microservices application

Subscribe

REST(JSON/HTTP)

Microservice

Microservice

broker

API

MicroservicePublish

API

REST(JSON/HTTP)

Publish

ServiceRegistry

API

Microservice

Page 7: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Microservices sample apps…

Create a single service

Rebuild a pre-baked microservices application

CluelessNo idea

ConfidentHas read all the

things!

ExperiencedHands-on understanding

Puzzled / RealisticChallenges are real

Page 8: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Enter… GameOn!

� Hands on with microservices

� Stick with ’Hello World’ simplicity

� Choose your own adventure

� Fast path to the hard stuff

� Build something cool (to you!)

� Learn as you go

Page 9: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Twelve Factors

� “a methodology for building software-as-a-service applications”

◦ Created by developers at Heroku

� Factors are independent of

◦ programming language,

◦ backing services,

◦ cloud provider

� http://12factor.net/

Page 10: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

At first…

ELK mongo

room

Player

Proxy

JSON/HTTP (REST)

Concierge

Page 11: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

… and now!

kafkaELK amalgam8couchdb

room

PlayerAuth

SweepProxystatic

MediatorMap

Page 12: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

About Dragons and Tombstones

� Problem: Maintaining a centered, densely packed grid of rooms

� SQL is hard.� CouchDB uses javascript to create

custom indexes� BUT: Deleting rooms leaves

tombstones. They never go away.

Page 13: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

The Map API

� Site has Name, Position (X, Y), Connection information to the WebService and a list of its Doors.

� CRUD service; when you retrieve a room, you get a list of its adjacent rooms

Page 14: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

The Map API{

"name":"First Room","connectionDetails":{

…, "target":"ws://secondroom:9008/barn/ws",… },

"fullName":"The First Room","description":"A helpful room with doors in every possible direction.","repositoryUrl":"https://github.com/your-fork","doors":{

"n":"A knobbly wooden door with a rough carving or a friendly face","w":"A fake wooden door with stickers of friendly faces plastered all over it","s":"A warped wooden door with a friendly face branded on the corner","e":"A polished wooden door with an inlaid friendly face",

}}

Page 15: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

The Map Internals, version 1

� Literally a copy of what’s exposed� Hard to store references to other rooms

� Room pre-allocation and movement make it cumbersom� No way to (really) delete rooms (!)

Page 16: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Map.stream().toGraph()

� A Map is a Collection of Rooms connected thru Doors� X connected to Y is… a graph!

Page 17: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

A graph, really?

First Room

Play Room

Basement

Dungeon

Page 18: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Take 1: Neo4J

� Created rooms using Neo4J APIs and Cypher query language� No easy way to do CRUD operations◦ Convert from object to Cypher using inspection

� In the end, just changing who was holding our chain…

Page 19: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Take 2: JNoSQL!

Page 20: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

What is JNoSQL?

� Mapping API - Artemis

� Communication API - Diana

� No lock-in

� Divide and conquer

DAO

Communication

Mapping

JNoS

QL

Page 21: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Eclipse JNoSQL

� Eclipse Foundation� Apache v2 + EPL 1.0

� API to each NoSQL type� Configurable� Extensible Communication

Mapping

Page 22: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

JNoSQL – Diana APIs

Key/Value Document

Column Family

Graph

Page 23: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Names & Definitions

� Annotated Entities� Template� Repository� Configuration

Page 24: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Annotaded Entities

� MappedSuperclass� Entity� Column

@Entitypublic class Site {

@Idprivate Long id;

@Columnprivate String name;

…}

Page 25: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Template

@Injectprivate GraphTemplate template;

public Optional<Site> getRecentRoom() {return template.getTraversalVertex().has("doorAvailable", true).<Site>stream().sorted(ORDER_WEIGHT).findFirst();

}

Page 26: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Repository

public interface SiteRepository extends Repository<Site, Long> {Optional<Site> findByName(String name);

}

@Inject@Database(GRAPH)private SiteRepository repository;

Page 27: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Repository@Transactionalpublic void save(Site site) {

if (isNull(site.getId())) {Optional<Site> siteByName = repository.findByName(site.getName());siteByName.ifPresent(site::merge);

}repository.save(site);

}

public Optional<Site> findByName(String name) {return repository.findByName(name);

}

Page 28: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

The future & possibilities

Page 29: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Why a graph makes MUCH sense?

� Current 2D map is VERY limiting◦ With a graph we can go 3D!

� Different kinds of objects can be tracked: ◦ Items can be made unique and migrate

� Other doors are possible!

Page 30: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Why a graph makes MUCH sense?

First Room

Play Room

Basement

Dungeon

The One Ring

Suite

Page 31: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Get involved!

� https://gameontext.slack.com� https://gameontext.org� http://jnosql.org� https://github.com/leomrlima/gameon-graph-map

Page 32: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

? & !

Page 33: JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

GameOn

! + JNoSQL

#JavaOne #JNoSQL @KateStanley91 @leomrlima @otaviojava

Thanks!