SlideShare a Scribd company logo
1 of 68
Download to read offline
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Next Generation
Spring Data and MongoDB
Mat Keep | Christoph Strobl
Mat Keep
Senior Director, Product Team
Christoph Strobl
Software Engineer, Spring Data
MongoDB 4.0
Multi Document Transactions
1
Spring Data - Lovelace
Sessions & Transactions
2
Alyson Crabal
Product Manager, Server
Jeff Yemin
Lead Engineer, Drivers
3
MongoDB 4.0:
Multi-Document ACID Transactions
4
Safe Harbor Statement
This presentation contains “forward-looking statements” within the meaning of Section 27A of the
Securities Act of 1933, as amended, and Section 21E of the Securities Exchange Act of 1934, as
amended. Such forward-looking statements are subject to a number of risks, uncertainties, assumptions
and other factors that could cause actual results and the timing of certain events to differ materially from
future results expressed or implied by the forward-looking statements. Factors that could cause or
contribute to such differences include, but are not limited to, those identified our filings with the Securities
and Exchange Commission. You should not rely upon forward-looking statements as predictions of future
events. Furthermore, such forward-looking statements speak only as of the date of this presentation.
In particular, the development, release, and timing of any features or functionality described for MongoDB
products remains at MongoDB’s sole discretion. This information is merely intended to outline our general
product direction and it should not be relied on in making a purchasing decision nor is this a commitment,
promise or legal obligation to deliver any material, code, or functionality. Except as required by law, we
undertake no obligation to update any forward-looking statements to reflect events or circumstances after
the date of such statements.
5
Intelligent Operational Data Platform
Best way to work
with data
Intelligently put data
where you want it
Freedom to run
anywhere
6
Data Models and Transactions
Tabular (Relational) Database
Related data split across multiple records and tables.
Multi-record transactions essential
Different databases take different approaches
Document Database
Related data contained in a single, rich document.
Transaction scoped to the document
7
Relational data model
Updating a contact’s details after they change
jobs means modifying multiple tables
Data Models and Transactions
8
Document
Database
Atomic single document operations
Updating a contact’s details after they change jobs means
atomically modifying multiple fields in a single document
Data Models and Transactions
9
Document
Database
For many apps, single
document transactions
meet data integrity
needs
Data Models and Transactions
10
MongoDB Multi-Document Transactions
Just like relational transactions
•  Multi-statement, familiar relational syntax
•  Easy to add to any application
•  Multiple documents in 1 or many collections
ACID guarantees
•  Snapshot isolation, all or nothing execution
•  No performance impact for single document operations
Schedule
•  MongoDB 4.0: Replica Set (Summer 2018)
•  MongoDB 4.2: extended to sharded clusters
11
Natural for developers
●  Idiomatic to the programming
language
●  Familiar to relational
developers
●  Simple
MongoDB Transactions Syntax
try (ClientSession clientSession =client.startSession())
{
clientSession.startTransaction();
try {
collection.insertOne(clientSession, docOne);
collection.insertOne(clientSession, docTwo);
clientSession.commitTransaction();
} catch (Exception e) {
clientSession.abortTransaction();
}
}
12
Natural for developers
●  Idiomatic to the programming
language
●  Familiar to relational
developers
●  Simple
with client.start_session() as s:
s.start_transaction()
try:
collection.insert_one(doc1, session=s)
collection.insert_one(doc2, session=s)
s.commit_transaction()
except Exception:
s.abort_transaction()
MongoDB Transactions Syntax
13
s.start_transaction()
orders.insert_one(order, session=s)
stock.update_one(item, stockUpdate, session=s)
s.commit_transaction()
db.start_transaction()
cursor.execute(orderInsert, orderData)
cursor.execute(stockUpdate, stockData)
db.commit()
*
Comparing Syntax with Tabular Databases
14
Best Practices
•  Existing single document atomicity guarantees
will meet 80%+ of your needs!
•  Transactions automatically abort after 60
seconds – TUNABLE
•  No more than 1,000 documents modified in a
single transaction
•  Add application logic that catches and retries
transactions aborted due to temporary
exceptions (aborted transactions are fully rolled
back by the database)
15
Our Journey to ACID Transactions
Major engineering investment over 3+ years touching every part of
the server and drivers
•  Storage layer
•  Replication consensus protocol
•  Sharding architecture
•  Consistency and durability guarantees
•  Global logical clock
•  Cluster metadata management
•  Exposed to drivers through API enhancements
16
What’s Done, What’s Left
17
Systems of Engagement
Web, mobile, IoT, social apps, content, personalization, single view,
mainframe offload
Systems
of Insight
Operational intelligence, data science,
data lake
Systems of Record
Back office LoB legacy modernization: billing, payment and order
processing, supply chain
MongoDB:
Easier to Address Complete Range of Use Cases
18
Learn More
Transactions Page
●  Documentation
●  Chalk and talks
Download the Release
Candidate
19
Spring
Transactions
MongoDBData
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
20
The Lovelace Release
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
21
The Lovelace Release
Client SessionsValidator TransactionsChange Streams
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
22
The Lovelace Release - Validator
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
23
The Lovelace Release - JSON Schema
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
24
The Lovelace Release - JSON Schema
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
25
The Lovelace Release - JSON Schema
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
26
The Lovelace Release - JSON Schema
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
27
The Lovelace Release - Change Streams
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
28
The Lovelace Release - Client Sessions
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
29
@EnableTransactionManagement
TransactionTemplate
@Transactional
PlatformTransactionManager
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
30
@EnableTransactionManagement
TransactionTemplate
@Transactional
PlatformTransactionManager
Flux
.flatMap(…
.then(…
.onError(…
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
31
@Configuration
@EnableMongoRepositories
public class MongoConfiguration extends AbstractMongoConfiguration {
@Bean
public MongoClient mongoClient() {
return new MongoClient(
}
@Override
protected String getDatabaseName() {
return "...
}
}
Full Control
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
32
@Configuration
@EnableMongoRepositories
public class MongoConfiguration extends AbstractMongoConfiguration {
@Bean
public MongoClient mongoClient() {
return new MongoClient(
}
@Override
protected String getDatabaseName() {
return "...
}
}
Full Control
new MongoClientURI("…?replicaSet=rs0")); !
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
33
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ops.insert(documentOne);
ops.insert(documentTwo);
}
}
Full Control
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
34
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
}
}
Full Control
ClientSession session = client.startSession();
session.startTransaction();
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
35
Full Control
ClientSession session = client.startSession();
session.startTransaction();
session.commitTransaction();
try {
} catch (Exception e) {
session.abortTransaction();
}
session.close();
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
}
}
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
36
Full Control
ClientSession session = client.startSession();
session.startTransaction();
session.commitTransaction();
try {
} catch (Exception e) {
session.abortTransaction();
}
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
action.insert(documentTwo);
return "OK";
});
session.close();
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
}
}
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
37
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ClientSession session = client.startSession();
session.startTransaction();
try {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
session.commitTransaction();
} catch (Exception e) {
session.abortTransaction();
}
session.close();
}
}
1
{ insert: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1,
startTransaction: true,
documents: [ { ... } ] }
1
Full Control
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
38
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ClientSession session = client.startSession();
session.startTransaction();
try {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
session.commitTransaction();
} catch (Exception e) {
session.abortTransaction();
}
session.close();
}
}
1
2
{ insert: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1,
startTransaction: true,
documents: [ { ... } ] }
1
{ insert: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1,
documents: [ { ... } ] }
2
Full Control
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
39
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ClientSession session = client.startSession();
session.startTransaction();
try {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
session.commitTransaction();
} catch (Exception e) {
session.abortTransaction();
}
session.close();
}
}
1
2
3
{ insert: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1,
startTransaction: true,
documents: [ { ... } ] }
1
{ insert: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1,
documents: [ { ... } ] }
2
{ commitTransaction: 1,
$db: "admin",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1 }
3
Full Control
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
40
Full Control
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ClientSession session = client.startSession();
session.startTransaction();
try {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
session.commitTransaction();
} catch (Exception e) {
session.abortTransaction();
}
session.close();
}
}
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
action.insert(documentTwo);
return "OK";
});
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
41
Full Control
@Service
public class PrettySimpleService {
final MongoOperations ops;
final MongoClient client;
public void insertDocuments() {
ClientSession session = client.startSession();
session.startTransaction();
try {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
session.commitTransaction();
} catch (Exception e) {
session.abortTransaction();
}
session.close();
}
}
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
action.insert(documentTwo);
action.getCollection("collection-1").insertOne(session, …
return "OK";
});
!
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
42
Collection / Meta Operations
@Configuration
@EnableMongoRepositories
public class MongoConfiguration extends AbstractMongoConfiguration {
@Bean
public MongoClient mongoClient() {
return new MongoClient(new MongoClientURI("…?replicaSet=rs0"));
}
@Override
protected String getDatabaseName() {
return "...
}
}
Collection / Meta operations don’t
work inside a transaction.
Create required structures upfront to
avoid frustration.
!
@EventListener
public void onApplicationEvent(ContextRefreshedEvent event) {
event.getApplicationContext().getBean(MongoOperations.class)
.createCollection(...)
} Use WriteConcern.MAJORITY to
avoid headaches.
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
43
The thing with Count
ClientSession session = client.startSession();
session.startTransaction();
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
return action.count(query(where("value").is("txn")), "collection-1");
});
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
44
The thing with Count
ClientSession session = client.startSession();
session.startTransaction();
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
return action.count(query(where("value").is("txn")), "collection-1");
}); { count: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } },
txnNumber: 1,
query: { "value" : "txn" } }
Command failed with error 50851 (Location50851):
Cannot run 'count' in a multi-document transaction.
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
45
The thing with Count
ClientSession session = client.startSession();
session.startTransaction();
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
return action.count(query(where("value").is("txn")), "collection-1");
}); { count: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } },
txnNumber: 1,
query: { "value" : "txn" } }
Command failed with error 50851 (Location50851):
Cannot run 'count' in a multi-document transaction.
{ aggregate: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } },
txnNumber: 1,
pipeline: [ { $match : { "value" : "txn" } },
{ $group : { "_id" : null, count : { $sum : 1} } } ] }
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
46
The thing with Count
ClientSession session = client.startSession();
session.startTransaction();
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
AggregationResults<Document> result = action.aggregate(
newAggregation(match(where("value").is("txn")),
count().as("count")),
"collection-1", Document.class);
return result.iterator().next().getLong("count");
});
{ aggregate: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } },
txnNumber: 1,
pipeline: [ { $match : { "value" : "txn" } },
{ $group : { "_id" : null, count : { $sum : 1} } } ] }
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
47
The thing with Count
ClientSession session = client.startSession();
session.startTransaction();
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
return action.execute("collection-1", collection ->
collection.countDocuments(session, Filters.eq("value", "txn")));
});

});
{ aggregate: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } },
txnNumber: 1,
pipeline: [ { $match : { "value" : "txn" } },
{ $group : { "_id" : null, count : { $sum : 1} } } ] }
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
{ aggregate: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } },
txnNumber: 1,
pipeline: [ { $match : { "value" : "txn" } },
{ $group : { "_id" : null, count : { $sum : 1} } } ] }
48
The thing with Count
ClientSession session = client.startSession();
session.startTransaction();
ops.withSession(()-> session)
.execute(action -> {
action.insert(documentOne);
return action.count(query(where("value").is("txn")), "collection-1");
});
RC1
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
49
@Configuration
@EnableMongoRepositories
public class MongoConfiguration extends AbstractMongoConfiguration {
@Bean
public MongoClient mongoClient() {
return new MongoClient(new MongoClientURI("…?replicaSet=rs0"));
}
@Override
protected String getDatabaseName() {
return "...
}
}
Declarative
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
50
@Configuration
@EnableMongoRepositories
public class MongoConfiguration extends AbstractMongoConfiguration {
@Bean
public MongoClient mongoClient() {
return new MongoClient(new MongoClientURI("…?replicaSet=rs0"));
}
@Override
protected String getDatabaseName() {
return "...
}
}
@Bean
PlatformTransactionManager transactionManager(MongoDbFactory dbFactory) {
return new MongoTransactionManager(dbFactory);
}
@EnableTransactionManagement
Declarative
!
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
51
@Service
public class PrettySimpleService {
final MongoOperations ops;
public void insertDocuments() {
}
}
final MongoClient client;
ClientSession session = client.startSession();
session.startTransaction();
try {
ops.withSession(session).insert(documentOne);
ops.withSession(session).insert(documentTwo);
session.commitTransaction();
} catch (Exception e) {
session.abortTransaction();
}
session.close();
Declarative
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
52
@Service
public class PrettySimpleService {
final MongoOperations ops;
public void insertDocuments() {
}
}
@Transactional
ops.insert(documentOne);
ops.insert(documentTwo);
Declarative
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
53
@Service
public class PrettySimpleService {
final MongoDbFactory dbFactory;
final MongoTemplate template;
public void insertDocuments() {
MongoTransactionManager txMgr = new MongoTransactionManager(dbFactory);
TransactionStatus status = txMgr.getTransaction(…
TransactionTemplate txTemplate = new TransactionTemplate(txMgr);
txTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status)
template.insert(documentOne);
template.insert(documentTwo);
}
});
txMgr.commit(status);
Transaction Template
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
54
Also works with
JTA, JPA, …
non native MongoDB transactions like
@Bean
public MongoOperations mongoTemplate(MongoDbFactory dbFactory) {
MongoTemplate template = new MongoTemplate(dbFactory);
template.setSessionSynchronization(SessionSynchronization.ALWAYS);
return template;
}
!
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
55
Reactive
Transactions
MongoDBFlux
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
56
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return …
});
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
57
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return Mono.from(collection.insertOne(session, documentOne))
});
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
58
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return Mono.from(collection.insertOne(session, documentOne))
.then(Mono.from(collection.insertOne(session, documentTwo)))
});
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
59
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return Mono.from(collection.insertOne(session, documentOne))
.then(Mono.from(collection.insertOne(session, documentTwo)))
.onErrorResume(e -> Mono.from(session.abortTransaction())
});
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
60
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return Mono.from(collection.insertOne(session, documentOne))
.then(Mono.from(collection.insertOne(session, documentTwo)))
.onErrorResume(e -> Mono.from(session.abortTransaction())
.then(Mono.error(e)))
});
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
61
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return Mono.from(collection.insertOne(session, documentOne))
.then(Mono.from(collection.insertOne(session, documentTwo)))
.onErrorResume(e -> Mono.from(session.abortTransaction())
.then(Mono.error(e)))
.flatMap(val -> Mono.from(session.commitTransaction())
.then(Mono.empty()))
});
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
62
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return Mono.from(collection.insertOne(session, documentOne))
.then(Mono.from(collection.insertOne(session, documentTwo)))
.onErrorResume(e -> Mono.from(session.abortTransaction())
.then(Mono.error(e)))
.flatMap(val -> Mono.from(session.commitTransaction())
.then(Mono.empty()))
.doFinally(signal -> session.close());
});
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
63
@Service
public class SimpleReactiveService {
final MongoClient client;
public Mono insertDocuments() {
MongoCollection collection = client.getDatabase(...
return Mono.from(client.startSession()).flatMap(session -> {
session.startTransaction();
return Mono.from(collection.insertOne(session, documentOne))
.then(Mono.from(collection.insertOne(session, documentTwo)))
.onErrorResume(e -> Mono.from(session.abortTransaction())
.then(Mono.error(e)))
.flatMap(val -> Mono.from(session.commitTransaction())
.then(Mono.empty()))
.doFinally(signal -> session.close());
});
}
Flux TX
1
2
3
{ insert: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1,
startTransaction: true,
documents: [ { ... } ] }
1
{ insert: "collection-1",
ordered: true,
$db: "db",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7
txnNumber: 1,
documents: [ { ... } ] }
2
{ commitTransaction: 1,
$db: "admin",
$clusterTime: { ... },
lsid: { id: { $binary: { base64 : "I3M7Nj...", ...
txnNumber: 1 }
3
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
64
@Service
public class SimpleReactiveService {
final ReactiveMongoOperations ops;
public Mono insertDocuments() {
return ops.inTransaction()
.execute(
action -> action.insert(documentOne)
.then(action.insert(documentTwo))
.then(Mono.empty());
}
}
Flux TX
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
@Service
public class SimpleReactiveService {
final ReactiveMongoOperations ops;
public Mono insertDocuments() {
return ops.inTransaction()
.execute(
action -> action.insert(documentOne)
.then(action.insert(documentTwo))
.then(Mono.empty());
}
}
65
Context
ReactiveMongoContext.getSession()
reactor.util.context.
Context
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
66
https://github.com/spring-projects/
spring-data-examples/tree/master/
mongodb/transactions
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
67
Reactive
in theFlux?
Yes!
Si!
Oui!
Evet!
да!
ya!
Ναί!
Ja!
@Transactional
public Mono insertDocuments()
@Deprecated
public ReactiveSessionScoped inTransaction()
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Next Generation
Spring Data and MongoDB
Mat Keep | Christoph Strobl

More Related Content

What's hot

Achieving the digital thread through PLM and ALM integration using oslc
Achieving the digital thread through PLM and ALM integration using oslcAchieving the digital thread through PLM and ALM integration using oslc
Achieving the digital thread through PLM and ALM integration using oslcAxel Reichwein
 
MongoDB and Azure Data Bricks - Microsoft
MongoDB and Azure Data Bricks - MicrosoftMongoDB and Azure Data Bricks - Microsoft
MongoDB and Azure Data Bricks - MicrosoftMongoDB
 
batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...
batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...
batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...BATbern
 
Digital Ethics and Privacy in a GDPR World
Digital Ethics and Privacy in a GDPR WorldDigital Ethics and Privacy in a GDPR World
Digital Ethics and Privacy in a GDPR WorldMongoDB
 
IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."
IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."
IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."Gustavo Cuervo
 
batbern43 Events - Lessons learnt building an Enterprise Data Bus
batbern43 Events - Lessons learnt building an Enterprise Data Busbatbern43 Events - Lessons learnt building an Enterprise Data Bus
batbern43 Events - Lessons learnt building an Enterprise Data BusBATbern
 
Modern data integration expert sessions
Modern data integration expert sessionsModern data integration expert sessions
Modern data integration expert sessionsJessicaMurrell3
 
LIVE DEMO: Big Data Suite
LIVE DEMO: Big Data SuiteLIVE DEMO: Big Data Suite
LIVE DEMO: Big Data SuiteVMware Tanzu
 
The Double win business transformation and in-year ROI and TCO reduction
The Double win business transformation and in-year ROI and TCO reductionThe Double win business transformation and in-year ROI and TCO reduction
The Double win business transformation and in-year ROI and TCO reductionMongoDB
 
IOOF Mongodb Australia
IOOF Mongodb AustraliaIOOF Mongodb Australia
IOOF Mongodb AustraliaMongoDB
 
MongoDB .local Toronto 2019: MongoDB – Powering the new age data demands
MongoDB .local Toronto 2019: MongoDB – Powering the new age data demandsMongoDB .local Toronto 2019: MongoDB – Powering the new age data demands
MongoDB .local Toronto 2019: MongoDB – Powering the new age data demandsMongoDB
 
Life is a Stream of Events
Life is a Stream of Events Life is a Stream of Events
Life is a Stream of Events confluent
 
MongoDB Europe 2016 - Welcome
MongoDB Europe 2016 - WelcomeMongoDB Europe 2016 - Welcome
MongoDB Europe 2016 - WelcomeMongoDB
 
Cloud Customer Architecture for Securing Workloads on Cloud Services
Cloud Customer Architecture for Securing Workloads on Cloud ServicesCloud Customer Architecture for Securing Workloads on Cloud Services
Cloud Customer Architecture for Securing Workloads on Cloud ServicesCloud Standards Customer Council
 
Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...
Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...
Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...confluent
 
Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...
Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...
Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...confluent
 
Final_CloudEventFrankfurt2017 (1).pdf
Final_CloudEventFrankfurt2017 (1).pdfFinal_CloudEventFrankfurt2017 (1).pdf
Final_CloudEventFrankfurt2017 (1).pdfMongoDB
 

What's hot (20)

Achieving the digital thread through PLM and ALM integration using oslc
Achieving the digital thread through PLM and ALM integration using oslcAchieving the digital thread through PLM and ALM integration using oslc
Achieving the digital thread through PLM and ALM integration using oslc
 
MongoDB and Azure Data Bricks - Microsoft
MongoDB and Azure Data Bricks - MicrosoftMongoDB and Azure Data Bricks - Microsoft
MongoDB and Azure Data Bricks - Microsoft
 
batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...
batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...
batbern43 Stream all Things: Patterns of Data Integration in Event Driven Sys...
 
Webinar Data Mesh - Part 3
Webinar Data Mesh - Part 3Webinar Data Mesh - Part 3
Webinar Data Mesh - Part 3
 
Digital Ethics and Privacy in a GDPR World
Digital Ethics and Privacy in a GDPR WorldDigital Ethics and Privacy in a GDPR World
Digital Ethics and Privacy in a GDPR World
 
IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."
IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."
IBM + REDHAT "Creating the World's Leading Hybrid Cloud Provider..."
 
batbern43 Events - Lessons learnt building an Enterprise Data Bus
batbern43 Events - Lessons learnt building an Enterprise Data Busbatbern43 Events - Lessons learnt building an Enterprise Data Bus
batbern43 Events - Lessons learnt building an Enterprise Data Bus
 
Modern data integration expert sessions
Modern data integration expert sessionsModern data integration expert sessions
Modern data integration expert sessions
 
Cloud Customer Architecture for Big Data and Analytics
Cloud Customer Architecture for Big Data and AnalyticsCloud Customer Architecture for Big Data and Analytics
Cloud Customer Architecture for Big Data and Analytics
 
LIVE DEMO: Big Data Suite
LIVE DEMO: Big Data SuiteLIVE DEMO: Big Data Suite
LIVE DEMO: Big Data Suite
 
The Double win business transformation and in-year ROI and TCO reduction
The Double win business transformation and in-year ROI and TCO reductionThe Double win business transformation and in-year ROI and TCO reduction
The Double win business transformation and in-year ROI and TCO reduction
 
Hyperledger: Market, Technology & Community Update
Hyperledger: Market, Technology & Community UpdateHyperledger: Market, Technology & Community Update
Hyperledger: Market, Technology & Community Update
 
IOOF Mongodb Australia
IOOF Mongodb AustraliaIOOF Mongodb Australia
IOOF Mongodb Australia
 
MongoDB .local Toronto 2019: MongoDB – Powering the new age data demands
MongoDB .local Toronto 2019: MongoDB – Powering the new age data demandsMongoDB .local Toronto 2019: MongoDB – Powering the new age data demands
MongoDB .local Toronto 2019: MongoDB – Powering the new age data demands
 
Life is a Stream of Events
Life is a Stream of Events Life is a Stream of Events
Life is a Stream of Events
 
MongoDB Europe 2016 - Welcome
MongoDB Europe 2016 - WelcomeMongoDB Europe 2016 - Welcome
MongoDB Europe 2016 - Welcome
 
Cloud Customer Architecture for Securing Workloads on Cloud Services
Cloud Customer Architecture for Securing Workloads on Cloud ServicesCloud Customer Architecture for Securing Workloads on Cloud Services
Cloud Customer Architecture for Securing Workloads on Cloud Services
 
Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...
Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...
Kafka Connect and KSQL: Useful Tools in Migrating from a Legacy System to Kaf...
 
Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...
Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...
Driving Business Transformation with Real-Time Analytics Using Apache Kafka a...
 
Final_CloudEventFrankfurt2017 (1).pdf
Final_CloudEventFrankfurt2017 (1).pdfFinal_CloudEventFrankfurt2017 (1).pdf
Final_CloudEventFrankfurt2017 (1).pdf
 

Similar to Next-Generation Spring Data and MongoDB

Accelerating a Path to Digital with a Cloud Data Strategy
Accelerating a Path to Digital with a Cloud Data StrategyAccelerating a Path to Digital with a Cloud Data Strategy
Accelerating a Path to Digital with a Cloud Data StrategyMongoDB
 
Achieving High Throughput With Reliability In Transactional Systems
Achieving High Throughput With Reliability In Transactional SystemsAchieving High Throughput With Reliability In Transactional Systems
Achieving High Throughput With Reliability In Transactional SystemsVMware Tanzu
 
Accelerating a Path to Digital With a Cloud Data Strategy
Accelerating a Path to Digital With a Cloud Data StrategyAccelerating a Path to Digital With a Cloud Data Strategy
Accelerating a Path to Digital With a Cloud Data StrategyMongoDB
 
Microservices Patterns with GoldenGate
Microservices Patterns with GoldenGateMicroservices Patterns with GoldenGate
Microservices Patterns with GoldenGateJeffrey T. Pollock
 
Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Solace
 
MongoDB - General Purpose Database
MongoDB - General Purpose DatabaseMongoDB - General Purpose Database
MongoDB - General Purpose DatabaseAshnikbiz
 
#dbhouseparty - Should I be building Microservices?
#dbhouseparty - Should I be building Microservices?#dbhouseparty - Should I be building Microservices?
#dbhouseparty - Should I be building Microservices?Tammy Bednar
 
Horses for Courses: Database Roundtable
Horses for Courses: Database RoundtableHorses for Courses: Database Roundtable
Horses for Courses: Database RoundtableEric Kavanagh
 
It's all about Integration - Developing with Oracle Cloud Services
It's all about Integration - Developing with Oracle Cloud ServicesIt's all about Integration - Developing with Oracle Cloud Services
It's all about Integration - Developing with Oracle Cloud ServicesOPITZ CONSULTING Deutschland
 
Deep Dive into Pivotal Cloud Foundry 2.0
Deep Dive into Pivotal Cloud Foundry 2.0Deep Dive into Pivotal Cloud Foundry 2.0
Deep Dive into Pivotal Cloud Foundry 2.0VMware Tanzu
 
Migrating from Big Data Architecture to Spring Cloud
Migrating from Big Data Architecture to Spring CloudMigrating from Big Data Architecture to Spring Cloud
Migrating from Big Data Architecture to Spring CloudVMware Tanzu
 
Scaling Database Modernisation with MongoDB - Infosys
Scaling Database Modernisation with MongoDB - InfosysScaling Database Modernisation with MongoDB - Infosys
Scaling Database Modernisation with MongoDB - InfosysMongoDB
 
InterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloud
InterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloudInterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloud
InterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloudiMasters
 
Cloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service OptionCloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service OptionDenodo
 
Mdb dn 2017_14b_cloud_foundry
Mdb dn 2017_14b_cloud_foundryMdb dn 2017_14b_cloud_foundry
Mdb dn 2017_14b_cloud_foundryDaniel M. Farrell
 
Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...
Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...
Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...Igor De Souza
 
Future of Data Strategy (ASEAN)
Future of Data Strategy (ASEAN)Future of Data Strategy (ASEAN)
Future of Data Strategy (ASEAN)Denodo
 
Pivotal Big Data Suite: A Technical Overview
Pivotal Big Data Suite: A Technical OverviewPivotal Big Data Suite: A Technical Overview
Pivotal Big Data Suite: A Technical OverviewVMware Tanzu
 

Similar to Next-Generation Spring Data and MongoDB (20)

Accelerating a Path to Digital with a Cloud Data Strategy
Accelerating a Path to Digital with a Cloud Data StrategyAccelerating a Path to Digital with a Cloud Data Strategy
Accelerating a Path to Digital with a Cloud Data Strategy
 
Achieving High Throughput With Reliability In Transactional Systems
Achieving High Throughput With Reliability In Transactional SystemsAchieving High Throughput With Reliability In Transactional Systems
Achieving High Throughput With Reliability In Transactional Systems
 
Accelerating a Path to Digital With a Cloud Data Strategy
Accelerating a Path to Digital With a Cloud Data StrategyAccelerating a Path to Digital With a Cloud Data Strategy
Accelerating a Path to Digital With a Cloud Data Strategy
 
Microservices Patterns with GoldenGate
Microservices Patterns with GoldenGateMicroservices Patterns with GoldenGate
Microservices Patterns with GoldenGate
 
Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture Introduction to Event-Driven Architecture
Introduction to Event-Driven Architecture
 
MongoDB - General Purpose Database
MongoDB - General Purpose DatabaseMongoDB - General Purpose Database
MongoDB - General Purpose Database
 
#dbhouseparty - Should I be building Microservices?
#dbhouseparty - Should I be building Microservices?#dbhouseparty - Should I be building Microservices?
#dbhouseparty - Should I be building Microservices?
 
Horses for Courses: Database Roundtable
Horses for Courses: Database RoundtableHorses for Courses: Database Roundtable
Horses for Courses: Database Roundtable
 
It's all about Integration - Developing with Oracle Cloud Services
It's all about Integration - Developing with Oracle Cloud ServicesIt's all about Integration - Developing with Oracle Cloud Services
It's all about Integration - Developing with Oracle Cloud Services
 
Deep Dive into Pivotal Cloud Foundry 2.0
Deep Dive into Pivotal Cloud Foundry 2.0Deep Dive into Pivotal Cloud Foundry 2.0
Deep Dive into Pivotal Cloud Foundry 2.0
 
Build vs Migrate to PaaS
Build vs Migrate to PaaSBuild vs Migrate to PaaS
Build vs Migrate to PaaS
 
Migrating from Big Data Architecture to Spring Cloud
Migrating from Big Data Architecture to Spring CloudMigrating from Big Data Architecture to Spring Cloud
Migrating from Big Data Architecture to Spring Cloud
 
Scaling Database Modernisation with MongoDB - Infosys
Scaling Database Modernisation with MongoDB - InfosysScaling Database Modernisation with MongoDB - Infosys
Scaling Database Modernisation with MongoDB - Infosys
 
InterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloud
InterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloudInterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloud
InterCon 2016 - SLA vs Agilidade: uso de microserviços e monitoramento de cloud
 
Api enablement-mainframe
Api enablement-mainframeApi enablement-mainframe
Api enablement-mainframe
 
Cloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service OptionCloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service Option
 
Mdb dn 2017_14b_cloud_foundry
Mdb dn 2017_14b_cloud_foundryMdb dn 2017_14b_cloud_foundry
Mdb dn 2017_14b_cloud_foundry
 
Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...
Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...
Data Engineer, Patterns & Architecture The future: Deep-dive into Microservic...
 
Future of Data Strategy (ASEAN)
Future of Data Strategy (ASEAN)Future of Data Strategy (ASEAN)
Future of Data Strategy (ASEAN)
 
Pivotal Big Data Suite: A Technical Overview
Pivotal Big Data Suite: A Technical OverviewPivotal Big Data Suite: A Technical Overview
Pivotal Big Data Suite: A Technical Overview
 

More from VMware Tanzu

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItVMware Tanzu
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023VMware Tanzu
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleVMware Tanzu
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023VMware Tanzu
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductVMware Tanzu
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready AppsVMware Tanzu
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And BeyondVMware Tanzu
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfVMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023VMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023VMware Tanzu
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptxVMware Tanzu
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchVMware Tanzu
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishVMware Tanzu
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVMware Tanzu
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - FrenchVMware Tanzu
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023VMware Tanzu
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootVMware Tanzu
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerVMware Tanzu
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeVMware Tanzu
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsVMware Tanzu
 

More from VMware Tanzu (20)

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Next-Generation Spring Data and MongoDB

  • 1. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Next Generation Spring Data and MongoDB Mat Keep | Christoph Strobl
  • 2. Mat Keep Senior Director, Product Team Christoph Strobl Software Engineer, Spring Data MongoDB 4.0 Multi Document Transactions 1 Spring Data - Lovelace Sessions & Transactions 2 Alyson Crabal Product Manager, Server Jeff Yemin Lead Engineer, Drivers
  • 4. 4 Safe Harbor Statement This presentation contains “forward-looking statements” within the meaning of Section 27A of the Securities Act of 1933, as amended, and Section 21E of the Securities Exchange Act of 1934, as amended. Such forward-looking statements are subject to a number of risks, uncertainties, assumptions and other factors that could cause actual results and the timing of certain events to differ materially from future results expressed or implied by the forward-looking statements. Factors that could cause or contribute to such differences include, but are not limited to, those identified our filings with the Securities and Exchange Commission. You should not rely upon forward-looking statements as predictions of future events. Furthermore, such forward-looking statements speak only as of the date of this presentation. In particular, the development, release, and timing of any features or functionality described for MongoDB products remains at MongoDB’s sole discretion. This information is merely intended to outline our general product direction and it should not be relied on in making a purchasing decision nor is this a commitment, promise or legal obligation to deliver any material, code, or functionality. Except as required by law, we undertake no obligation to update any forward-looking statements to reflect events or circumstances after the date of such statements.
  • 5. 5 Intelligent Operational Data Platform Best way to work with data Intelligently put data where you want it Freedom to run anywhere
  • 6. 6 Data Models and Transactions Tabular (Relational) Database Related data split across multiple records and tables. Multi-record transactions essential Different databases take different approaches Document Database Related data contained in a single, rich document. Transaction scoped to the document
  • 7. 7 Relational data model Updating a contact’s details after they change jobs means modifying multiple tables Data Models and Transactions
  • 8. 8 Document Database Atomic single document operations Updating a contact’s details after they change jobs means atomically modifying multiple fields in a single document Data Models and Transactions
  • 9. 9 Document Database For many apps, single document transactions meet data integrity needs Data Models and Transactions
  • 10. 10 MongoDB Multi-Document Transactions Just like relational transactions •  Multi-statement, familiar relational syntax •  Easy to add to any application •  Multiple documents in 1 or many collections ACID guarantees •  Snapshot isolation, all or nothing execution •  No performance impact for single document operations Schedule •  MongoDB 4.0: Replica Set (Summer 2018) •  MongoDB 4.2: extended to sharded clusters
  • 11. 11 Natural for developers ●  Idiomatic to the programming language ●  Familiar to relational developers ●  Simple MongoDB Transactions Syntax try (ClientSession clientSession =client.startSession()) { clientSession.startTransaction(); try { collection.insertOne(clientSession, docOne); collection.insertOne(clientSession, docTwo); clientSession.commitTransaction(); } catch (Exception e) { clientSession.abortTransaction(); } }
  • 12. 12 Natural for developers ●  Idiomatic to the programming language ●  Familiar to relational developers ●  Simple with client.start_session() as s: s.start_transaction() try: collection.insert_one(doc1, session=s) collection.insert_one(doc2, session=s) s.commit_transaction() except Exception: s.abort_transaction() MongoDB Transactions Syntax
  • 13. 13 s.start_transaction() orders.insert_one(order, session=s) stock.update_one(item, stockUpdate, session=s) s.commit_transaction() db.start_transaction() cursor.execute(orderInsert, orderData) cursor.execute(stockUpdate, stockData) db.commit() * Comparing Syntax with Tabular Databases
  • 14. 14 Best Practices •  Existing single document atomicity guarantees will meet 80%+ of your needs! •  Transactions automatically abort after 60 seconds – TUNABLE •  No more than 1,000 documents modified in a single transaction •  Add application logic that catches and retries transactions aborted due to temporary exceptions (aborted transactions are fully rolled back by the database)
  • 15. 15 Our Journey to ACID Transactions Major engineering investment over 3+ years touching every part of the server and drivers •  Storage layer •  Replication consensus protocol •  Sharding architecture •  Consistency and durability guarantees •  Global logical clock •  Cluster metadata management •  Exposed to drivers through API enhancements
  • 17. 17 Systems of Engagement Web, mobile, IoT, social apps, content, personalization, single view, mainframe offload Systems of Insight Operational intelligence, data science, data lake Systems of Record Back office LoB legacy modernization: billing, payment and order processing, supply chain MongoDB: Easier to Address Complete Range of Use Cases
  • 18. 18 Learn More Transactions Page ●  Documentation ●  Chalk and talks Download the Release Candidate
  • 20. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20 The Lovelace Release
  • 21. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 21 The Lovelace Release Client SessionsValidator TransactionsChange Streams
  • 22. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 22 The Lovelace Release - Validator
  • 23. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 23 The Lovelace Release - JSON Schema
  • 24. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 24 The Lovelace Release - JSON Schema
  • 25. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25 The Lovelace Release - JSON Schema
  • 26. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 26 The Lovelace Release - JSON Schema
  • 27. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 27 The Lovelace Release - Change Streams
  • 28. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 28 The Lovelace Release - Client Sessions
  • 29. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 29 @EnableTransactionManagement TransactionTemplate @Transactional PlatformTransactionManager
  • 30. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 30 @EnableTransactionManagement TransactionTemplate @Transactional PlatformTransactionManager Flux .flatMap(… .then(… .onError(…
  • 31. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 31 @Configuration @EnableMongoRepositories public class MongoConfiguration extends AbstractMongoConfiguration { @Bean public MongoClient mongoClient() { return new MongoClient( } @Override protected String getDatabaseName() { return "... } } Full Control
  • 32. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 32 @Configuration @EnableMongoRepositories public class MongoConfiguration extends AbstractMongoConfiguration { @Bean public MongoClient mongoClient() { return new MongoClient( } @Override protected String getDatabaseName() { return "... } } Full Control new MongoClientURI("…?replicaSet=rs0")); !
  • 33. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 33 @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ops.insert(documentOne); ops.insert(documentTwo); } } Full Control
  • 34. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 34 @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); } } Full Control ClientSession session = client.startSession(); session.startTransaction();
  • 35. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 35 Full Control ClientSession session = client.startSession(); session.startTransaction(); session.commitTransaction(); try { } catch (Exception e) { session.abortTransaction(); } session.close(); @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); } }
  • 36. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 36 Full Control ClientSession session = client.startSession(); session.startTransaction(); session.commitTransaction(); try { } catch (Exception e) { session.abortTransaction(); } ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); action.insert(documentTwo); return "OK"; }); session.close(); @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); } }
  • 37. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 37 @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ClientSession session = client.startSession(); session.startTransaction(); try { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); session.commitTransaction(); } catch (Exception e) { session.abortTransaction(); } session.close(); } } 1 { insert: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1, startTransaction: true, documents: [ { ... } ] } 1 Full Control
  • 38. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 38 @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ClientSession session = client.startSession(); session.startTransaction(); try { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); session.commitTransaction(); } catch (Exception e) { session.abortTransaction(); } session.close(); } } 1 2 { insert: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1, startTransaction: true, documents: [ { ... } ] } 1 { insert: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1, documents: [ { ... } ] } 2 Full Control
  • 39. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 39 @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ClientSession session = client.startSession(); session.startTransaction(); try { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); session.commitTransaction(); } catch (Exception e) { session.abortTransaction(); } session.close(); } } 1 2 3 { insert: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1, startTransaction: true, documents: [ { ... } ] } 1 { insert: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1, documents: [ { ... } ] } 2 { commitTransaction: 1, $db: "admin", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1 } 3 Full Control
  • 40. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 40 Full Control @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ClientSession session = client.startSession(); session.startTransaction(); try { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); session.commitTransaction(); } catch (Exception e) { session.abortTransaction(); } session.close(); } } ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); action.insert(documentTwo); return "OK"; });
  • 41. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 41 Full Control @Service public class PrettySimpleService { final MongoOperations ops; final MongoClient client; public void insertDocuments() { ClientSession session = client.startSession(); session.startTransaction(); try { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); session.commitTransaction(); } catch (Exception e) { session.abortTransaction(); } session.close(); } } ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); action.insert(documentTwo); action.getCollection("collection-1").insertOne(session, … return "OK"; }); !
  • 42. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 42 Collection / Meta Operations @Configuration @EnableMongoRepositories public class MongoConfiguration extends AbstractMongoConfiguration { @Bean public MongoClient mongoClient() { return new MongoClient(new MongoClientURI("…?replicaSet=rs0")); } @Override protected String getDatabaseName() { return "... } } Collection / Meta operations don’t work inside a transaction. Create required structures upfront to avoid frustration. ! @EventListener public void onApplicationEvent(ContextRefreshedEvent event) { event.getApplicationContext().getBean(MongoOperations.class) .createCollection(...) } Use WriteConcern.MAJORITY to avoid headaches.
  • 43. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 43 The thing with Count ClientSession session = client.startSession(); session.startTransaction(); ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); return action.count(query(where("value").is("txn")), "collection-1"); });
  • 44. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 44 The thing with Count ClientSession session = client.startSession(); session.startTransaction(); ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); return action.count(query(where("value").is("txn")), "collection-1"); }); { count: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } }, txnNumber: 1, query: { "value" : "txn" } } Command failed with error 50851 (Location50851): Cannot run 'count' in a multi-document transaction.
  • 45. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 45 The thing with Count ClientSession session = client.startSession(); session.startTransaction(); ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); return action.count(query(where("value").is("txn")), "collection-1"); }); { count: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } }, txnNumber: 1, query: { "value" : "txn" } } Command failed with error 50851 (Location50851): Cannot run 'count' in a multi-document transaction. { aggregate: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } }, txnNumber: 1, pipeline: [ { $match : { "value" : "txn" } }, { $group : { "_id" : null, count : { $sum : 1} } } ] }
  • 46. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 46 The thing with Count ClientSession session = client.startSession(); session.startTransaction(); ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); AggregationResults<Document> result = action.aggregate( newAggregation(match(where("value").is("txn")), count().as("count")), "collection-1", Document.class); return result.iterator().next().getLong("count"); }); { aggregate: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } }, txnNumber: 1, pipeline: [ { $match : { "value" : "txn" } }, { $group : { "_id" : null, count : { $sum : 1} } } ] }
  • 47. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 47 The thing with Count ClientSession session = client.startSession(); session.startTransaction(); ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); return action.execute("collection-1", collection -> collection.countDocuments(session, Filters.eq("value", "txn"))); });
 }); { aggregate: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } }, txnNumber: 1, pipeline: [ { $match : { "value" : "txn" } }, { $group : { "_id" : null, count : { $sum : 1} } } ] }
  • 48. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ { aggregate: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... } } }, txnNumber: 1, pipeline: [ { $match : { "value" : "txn" } }, { $group : { "_id" : null, count : { $sum : 1} } } ] } 48 The thing with Count ClientSession session = client.startSession(); session.startTransaction(); ops.withSession(()-> session) .execute(action -> { action.insert(documentOne); return action.count(query(where("value").is("txn")), "collection-1"); }); RC1
  • 49. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 49 @Configuration @EnableMongoRepositories public class MongoConfiguration extends AbstractMongoConfiguration { @Bean public MongoClient mongoClient() { return new MongoClient(new MongoClientURI("…?replicaSet=rs0")); } @Override protected String getDatabaseName() { return "... } } Declarative
  • 50. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 50 @Configuration @EnableMongoRepositories public class MongoConfiguration extends AbstractMongoConfiguration { @Bean public MongoClient mongoClient() { return new MongoClient(new MongoClientURI("…?replicaSet=rs0")); } @Override protected String getDatabaseName() { return "... } } @Bean PlatformTransactionManager transactionManager(MongoDbFactory dbFactory) { return new MongoTransactionManager(dbFactory); } @EnableTransactionManagement Declarative !
  • 51. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 51 @Service public class PrettySimpleService { final MongoOperations ops; public void insertDocuments() { } } final MongoClient client; ClientSession session = client.startSession(); session.startTransaction(); try { ops.withSession(session).insert(documentOne); ops.withSession(session).insert(documentTwo); session.commitTransaction(); } catch (Exception e) { session.abortTransaction(); } session.close(); Declarative
  • 52. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 52 @Service public class PrettySimpleService { final MongoOperations ops; public void insertDocuments() { } } @Transactional ops.insert(documentOne); ops.insert(documentTwo); Declarative
  • 53. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 53 @Service public class PrettySimpleService { final MongoDbFactory dbFactory; final MongoTemplate template; public void insertDocuments() { MongoTransactionManager txMgr = new MongoTransactionManager(dbFactory); TransactionStatus status = txMgr.getTransaction(… TransactionTemplate txTemplate = new TransactionTemplate(txMgr); txTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) template.insert(documentOne); template.insert(documentTwo); } }); txMgr.commit(status); Transaction Template
  • 54. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 54 Also works with JTA, JPA, … non native MongoDB transactions like @Bean public MongoOperations mongoTemplate(MongoDbFactory dbFactory) { MongoTemplate template = new MongoTemplate(dbFactory); template.setSessionSynchronization(SessionSynchronization.ALWAYS); return template; } !
  • 55. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 55 Reactive Transactions MongoDBFlux
  • 56. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 56 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return … }); } Flux TX
  • 57. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 57 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return Mono.from(collection.insertOne(session, documentOne)) }); } Flux TX
  • 58. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 58 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return Mono.from(collection.insertOne(session, documentOne)) .then(Mono.from(collection.insertOne(session, documentTwo))) }); } Flux TX
  • 59. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 59 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return Mono.from(collection.insertOne(session, documentOne)) .then(Mono.from(collection.insertOne(session, documentTwo))) .onErrorResume(e -> Mono.from(session.abortTransaction()) }); } Flux TX
  • 60. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 60 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return Mono.from(collection.insertOne(session, documentOne)) .then(Mono.from(collection.insertOne(session, documentTwo))) .onErrorResume(e -> Mono.from(session.abortTransaction()) .then(Mono.error(e))) }); } Flux TX
  • 61. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 61 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return Mono.from(collection.insertOne(session, documentOne)) .then(Mono.from(collection.insertOne(session, documentTwo))) .onErrorResume(e -> Mono.from(session.abortTransaction()) .then(Mono.error(e))) .flatMap(val -> Mono.from(session.commitTransaction()) .then(Mono.empty())) }); } Flux TX
  • 62. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 62 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return Mono.from(collection.insertOne(session, documentOne)) .then(Mono.from(collection.insertOne(session, documentTwo))) .onErrorResume(e -> Mono.from(session.abortTransaction()) .then(Mono.error(e))) .flatMap(val -> Mono.from(session.commitTransaction()) .then(Mono.empty())) .doFinally(signal -> session.close()); }); } Flux TX
  • 63. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 63 @Service public class SimpleReactiveService { final MongoClient client; public Mono insertDocuments() { MongoCollection collection = client.getDatabase(... return Mono.from(client.startSession()).flatMap(session -> { session.startTransaction(); return Mono.from(collection.insertOne(session, documentOne)) .then(Mono.from(collection.insertOne(session, documentTwo))) .onErrorResume(e -> Mono.from(session.abortTransaction()) .then(Mono.error(e))) .flatMap(val -> Mono.from(session.commitTransaction()) .then(Mono.empty())) .doFinally(signal -> session.close()); }); } Flux TX 1 2 3 { insert: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1, startTransaction: true, documents: [ { ... } ] } 1 { insert: "collection-1", ordered: true, $db: "db", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7 txnNumber: 1, documents: [ { ... } ] } 2 { commitTransaction: 1, $db: "admin", $clusterTime: { ... }, lsid: { id: { $binary: { base64 : "I3M7Nj...", ... txnNumber: 1 } 3
  • 64. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 64 @Service public class SimpleReactiveService { final ReactiveMongoOperations ops; public Mono insertDocuments() { return ops.inTransaction() .execute( action -> action.insert(documentOne) .then(action.insert(documentTwo)) .then(Mono.empty()); } } Flux TX
  • 65. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @Service public class SimpleReactiveService { final ReactiveMongoOperations ops; public Mono insertDocuments() { return ops.inTransaction() .execute( action -> action.insert(documentOne) .then(action.insert(documentTwo)) .then(Mono.empty()); } } 65 Context ReactiveMongoContext.getSession() reactor.util.context. Context
  • 66. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 66 https://github.com/spring-projects/ spring-data-examples/tree/master/ mongodb/transactions
  • 67. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 67 Reactive in theFlux? Yes! Si! Oui! Evet! да! ya! Ναί! Ja! @Transactional public Mono insertDocuments() @Deprecated public ReactiveSessionScoped inTransaction()
  • 68. Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Next Generation Spring Data and MongoDB Mat Keep | Christoph Strobl