MongoDB 3.6: Here to SRV you with easier replica set connections
If you have logged into MongoDB Atlas recently – and you should, the entry-level tier is free! – you may have noticed a strange new syntax on 3.6 connection strings.
MongoDB Seed Lists
What is this
Well, in MongoDB 3.6 we introduced the concept of a seed list that is specified using DNS records, specifically SRV and TXT records. You will recall from using replica sets with MongoDB that the client must specify at least one replica set member (and may specify several of them) when connecting. This allows a client to connect to a replica set even if one of the nodes that the client specifies is unavailable.
You can see an example of this URL on a 3.4 cluster connection string:
Note that without the SRV record configuration we must list several nodes (in the case of Atlas we always include all the cluster members, though this is not required). We also have to specify the
With the 3.4 or earlier driver, we have to specify all the options on the command line using the MongoDB URI syntax.
The use of SRV records eliminates the requirement for every client to pass in a complete set of state information for the cluster. Instead, a single SRV record identifies all the nodes associated with the cluster (and their port numbers) and an associated TXT record defines the options for the URI.
Reading SRV and TXT Records
We can see how this works in practice on a MongoDB Atlas cluster with a simple Python script.
import srvlookup #pip install srvlookup import sys import dns.resolver #pip install dnspython host = None if len(sys.argv) > 1 : host = sys.argv if host : services = srvlookup.lookup("mongodb", domain=host) for i in services: print("%s:%i" % (i.hostname, i.port)) for txtrecord in dns.resolver.query(host, 'TXT'): print("%s: %s" % ( host, txtrecord)) else: print("No host specified")
We can run this script using the node specified in the 3.6 connection string as a parameter.
$ python mongodb_srv_records.py freeclusterjd-ffp4c.mongodb.net freeclusterjd-shard-00-00-ffp4c.mongodb.net:27017 freeclusterjd-shard-00-01-ffp4c.mongodb.net:27017 freeclusterjd-shard-00-02-ffp4c.mongodb.net:27017 freeclusterjd-ffp4c.mongodb.net: "authSource=admin&replicaSet=FreeClusterJD-shard-0" $
You can also do this lookup with nslookup:
JD10Gen-old:~ jdrumgoole$ nslookup > set type=SRV > _mongodb._tcp.rs.joedrumgoole.com Server: 10.65.141.1 Address: 10.65.141.1#53 Non-authoritative answer: _mongodb._tcp.rs.joedrumgoole.com service = 0 0 27022 rs1.joedrumgoole.com. _mongodb._tcp.rs.joedrumgoole.com service = 0 0 27022 rs2.joedrumgoole.com. _mongodb._tcp.rs.joedrumgoole.com service = 0 0 27022 rs3.joedrumgoole.com. Authoritative answers can be found from: > set type=TXT > rs.joedrumgoole.com Server: 10.65.141.1 Address: 10.65.141.1#53 Non-authoritative answer: rs.joedrumgoole.com text = "authSource=admin&replicaSet=srvdemo"
You can see how this could be used to construct a 3.4 style connection string by comparing it with the 3.4 connection string above.
As you can see, the complexity of the cluster and its configuration parameters are stored in the DNS server and hidden from the end user. If a node's IP address or name changes or we want to change the replica set name, this can all now be done completely transparently from the client’s perspective. We can also add and remove nodes from a cluster without impacting clients.
So now whenever you see
mongodb+srv you know you are expecting a SRV and TXT record to deliver the client connection string.
Creating SRV and TXT records
Of course, SRV and TXT records are not just for Atlas. You can also create your own SRV and TXT records for your self-hosted MongoDB clusters. All you need for this is edit access to your DNS server so you can add SRV and TXT records. In the examples that follow we are using the AWS Route 53 DNS service.
I have set up a demo replica set on AWS with a three-node setup. They are :
rs1.joedrumgoole.com rs2.joedrumgoole.com rs3.joedrumgoole.com
Each has a mongod process running on port 27022. I have set up a security group that allows access to my local laptop and the nodes themselves so they can see each other.
I also set up the DNS names for the above nodes in AWS Route 53.
We can start the mongod processes by running the following command on each node.
$ sudo /usr/local/m/versions/3.6.3/bin/mongod --auth --port 27022 --replSet srvdemo --bind_ip 0.0.0.0 --keyFile mdb_keyfile"
Now we need to set up the SRV and TXT records for this cluster.
The SRV record points to the server or servers that will comprise the members of the replica set. The TXT record defines the options for the replica set, specifically the database that will be used for authorization and the name of the replica set. It is important to note that the mongodb+srv format URI implicitly adds “ssl=true”. In our case SSL is not used for the demo so we have to append “&ssl=false” to the client connector. Note that the SRV record is specifically designed to look up the mongodb service referenced at the start of the URL.
The settings in AWS Route 53 are:
Which leads to the following entry in the zone file for Route 53.
Now we can add the TXT record. By convention, we use the same name as the SRV record (
rs.joedrumgoole.com) so that MongoDB knows where to find the TXT record.
We can do this on AWS Route 53 as follows:
This will create the following TXT record.
Now we can access this service as :
This will retrieve a complete URL and connection string which can then be used to contact the service.
The whole process is outlined below:
Once your records are set up, you can easily change port numbers without impacting clients and also add and remove cluster members.
SRV records are another way in which MongoDB is making life easier for database developers everywhere.
You should also check out full documentation on SRV and TXT records in MongoDB 3.6.
You can sign up for a free MongoDB Atlas tier which is suitable for single user use.
Find out how to use your favorite programming language with MongoDB via our MongoDB drivers.
Please visit MongoDB University for free online training in all aspects of MongoDB.
Follow Joe Drumgoole on twitter for more news about MongoDB.
Meet the team that builds MongoDB in-person at MongoDB World.
SEGA HARDlight Migrates to MongoDB Atlas to Simplify Ops and Improve Experience for Millions of Mobile Gamers
It was way back in the summer of ‘91 that Sonic the Hedgehog first chased rings across our 2D screens. Gaming has come a long way since then. From a static TV and console setup in ‘91, to online PC gaming in the noughties and now to mobile and virtual reality. Surprisingly, for most of those 25 years, the underlying infrastructure that powered these games hasn’t really changed much at all. It was all relational databases. But with ever increasing need for scale, flexibility and creativity in games, that’s changing fast. SEGA HARDlight is leading this shift by adopting a DevOps culture and using MongoDB Atlas, the cloud hosted MongoDB service, to deliver the best possible gaming experience.
Bringing Icons to Mobile Games
SEGA HARDlight is a mobile development studio for SEGA, a gaming company you might have heard of. Based in the UK’s Royal Leamington Spa, SEGA HARDlight is well known for bringing the much-loved blue mascot Sonic the Hedgehog to the small screen. Along with a range of Sonic games, HARDlight is also responsible for building and running a number of other iconic titles such as Crazy Taxi: City Rush and Kingdom Conquest: Dark Empire.
Earlier versions of the mobile games such as Sonic Jump and Sonic Dash didn’t require a connection to the internet and had no server functionality. As they were relatively static games, developers initially supported the releases with an in-house tech stack based around Java and MySQL and hosted in SEGA HARDlight’s own data centre.
The standard practice for launching these games involved load testing the servers to the point of breaking, then provisioning the resources to handle an acceptable failure point. This limited application functionality, and could cause service outages when reaching the provisioned resources’ breaking point. As the games started to add more online functionality and increased in popularity, that traditional stack started to creak.
Massive Adoption: Spiky Traffic
Mobile games have an interesting load pattern. People flock in extreme numbers very soon after the release. For the most popular games, this can mean many millions people in just a few days or even hours. The peak is usually short and then quickly drops to a long tail of dedicated players. Provisioning for this kind of traffic with a dynamic game is a major headache. The graph from the Crazy Taxi: City Rush launch in 2014 demonstrates just how spiky the traffic can be.
We spoke with Yordan Gyurchev, Technical Director at SEGA HARDlight, who explained: “With these massive volumes even minor changes in the database have a big impact. To provide a perfect gaming experience developers need to be intimately familiar with the performance trade offs of the database they’re using,”
SEGA HARDlight knew that the games were only going to get more online functionality and generate even more massive bursts of user activity. Much of the gaming data was also account-based so it didn’t fit naturally in the rows and columns of relational databases. In order to address these limitations, the team searched for alternatives. After reviewing Cassandra and Couchbase, but feeling they were either too complex to manage or didn’t have the mature support needed to support the company’s SLAs, the HARDlight engineers looked to MongoDB Atlas, the MongoDB database as a service.
Then came extensive evaluations and testing across multiple dimensions such as cost, maintenance, monitoring and backups. It was well known that MongoDB natively had the scalability and flexibility to handle large volumes and always-on deployments but HARDlight’s team had to have support on the operations side too.
Advanced operational tooling in MongoDB Atlas gave a small DevOps team of just two staffers the ability to handle and run games even as millions of people join the fray. They no longer had to worry about maintenance, upgrades or backups. In fact, one of the clinchers was the point in time backup and restore feature which meant that they can roll back to a checkpoint with the click of a button. With MongoDB Atlas and running on AWS, SEGA HARDlight was ready to take on even Boss Level scaling.
“At HARDlight we’re passionate about finding the right tool for the job. For us we could see that using a horizontally scalable document database was a perfect fit for player-account based games,” said Yordan.
“The ability to create a high traffic volume, highly scalable solution is about knowing the tiny details. To do that, normally engineers need to focus on many different parts of the stack but MongoDB Atlas and MongoDB’s support gives us a considerable shortcut. If this was handled in-house we would only be as good as our database expert. Now we can rely on a wealth of knowledge, expertise and best in class technology.”
HARDlight’s first MongoDB powered game was Kingdom Conquest: Dark Empire which was a frictionless launch from the start and gave the engineers their first experiences of MongoDB. Then in a weekend in late 2017 Sonic Forces: Speed Battle was launched on mobile. It’s a demanding, always-on application that enables constant connection to the internet and shared leaderboards. In the background a 3 shard cluster running on MongoDB Atlas easily scaled to handle the complex loads as millions of gamers joined the race. The database was stable with low latencies and not a single service interruption. All of this resulted in a low stress launch, a happy DevOps team and a very enthusiastic set of gamers.
Yordan concluded: “With MySQL, it had taken multiple game launches to get the database backend right. With MongoDB Atlas, big launches were a success right from the start. That’s no mean feat.”
Just as the gaming platforms have evolved and transformed through the years, so too has the database layer had to grow and adapt. SEGA HARDlight is now expanding its use of MongoDB Atlas to support all new games as they come online. By taking care of the operations, management and scaling, MongoDB Atlas lets HARDlight focus on building and running some of the most iconic games in the world. And doing it with confidence.
Gone is the 90s infrastructure. Replaced by a stack that is every bit as modern, powerful and fast as the famous blue hedgehog.
Start your Atlas journey today for free. What are you waiting for?
Hacking Unemployment: How DWP Digital and MongoDB are Working Together to Empower Developers and Tackle Some of the Biggest Challenges in the UK
Technology and businesses exist to do social good. We all have bills to pay and families to support, but beyond that, it has to be about more than profit. I also believe that developers in particular have a huge influence on what an organisation can achieve, both its social impact and the bottom line. The Department for Work and Pensions’ Digital team (DWP Digital) is the perfect example of a group that understands and embraces the important role developers can play solving major issues. This year we’ve been lucky enough to work with DWP Digital and its developers in the ultimate hope of tackling some of the UK’s biggest challenges.
The Department for Work and Pensions (DWP) is the UK’s biggest public service department. It’s responsible for allocating government help to those in need. This includes a range of benefits including the state pension, disability allowances and more. Over 22 million citizens rely on the £168 billion that DWP releases every year.
The DWP Digital team is the group responsible for building and supporting the applications that make this all possible. They operate more than 1,000 applications and estimate that more than 50 million lines of code have been written for these applications. Currently, there’s a major shift happening at DWP Digital, as much of the most important work is coming back in-house and developers are adopting a more agile approach to delivery. The aim is to deliver better, more efficient and more customer-focused services; and they could not do that without an engaged, skilled and creative team of developers.
Hack the NorthFor those who don’t know, a hackathon is an event that gives developers a chance to try out new technologies, solve new problems and experiment with new approaches. Basically, there are three things you want to get out of a hackathon: learn something, have fun and try to do some good. However, before we get into the hackathon, some statistics: In Manchester City and its surrounding areas there are more than 75,000 unemployed people living (Source: DWP’s Churchill application, June 2017) and the overall unemployment rate is above the national average with 5.5% of residents out of work (Source: Nomis, official labour market statistics). Jobs in the science, research, engineering and technology professions make up just 4.69% of the total workforce in Manchester. However, vacancies in that category make up 18% of the total vacancies advertised (Source: City Council Quarterly Economy Dashboard Q1 2016/2017 ). So when DWP Digital decided to run a hackathon ahead of the opening of its Manchester digital hub in early 2018, the big challenge they’d want to tackle was obvious. Hack the North was a two-day public hackathon focused on finding solutions to help address the unemployment problems in the city. It is usually done off-site in order to take the participants out of the headspace of day-to-day activity. There is normally plenty of food (pizza), beverages and competitive banter.
As DWP Digital is one of the biggest users of MongoDB in Europe and our developer advocacy team have experience running hackathons, a number of our team went up to support the event along with other sponsors ThoughtWorks and TechHub Manchester. I’ve been at a few hackathons through the years and, I have to say, this was one of the best I’ve been involved in. The quality of ideas, the execution and enthusiasm from all involved was fantastic.
We had more than 70 people onsite who divided into 10 distinct teams, each with a mission to deliver a new working solution in just two days using available data from public sources such as Churchill (DWP’s public data repository – which is also built on MongoDB).
"I’d expected DWP to be quite corporate, but the people I’ve met here really want to make a difference to the world.”— DWP Digital (@DWPDigital) December 11, 2017
Our @dtanham on the innovation & creativity on display at our #HackTheNorth #hackathon in #Manchester 🐝
👉🏽 https://t.co/NPbqhiSy6H pic.twitter.com/t2kmurOa5O
The final solutions were wide-ranging, creative and impressive. We had everything from an engine that helped the onboarding process for the newly unemployed, right through to a platform that gamified CV and aptitude testing. However, the eventual winner was a team called UpSkill. UpSkill built an application using MongoDB Atlas that could match people’s skills to the requirements of employers, and has an API to allow people to access resources to boost their skills. It was a very slick, very well executed final product and first among a great crop of ideas.
Admittedly we haven’t completely solved unemployment in Manchester, but to my eyes, the two-day event was a roaring success with the developers learning a lot and building some powerful proof of concepts. If you do want to see more, check out the #HackTheNorth Twitter moment or this excellent blog post from my fellow judge Dan Tanham, a Deputy Director at DWP Digital.
Learning to teach, teaching to learn
You’ve never truly learnt a lesson until you’ve taught it to someone else. Alongside the hackathon, another way DWP Digital keeps its team on the forefront of development best practices is by presenting at developer conferences. We were delighted to have dozens of the DWP Digital team come along to MongoDB Europe 2017 in London November of last year, but what was really special was to have Rob Thompson, CTO of DWP Digital, deliver one of the morning keynotes.
You can see the full video of his presentation below and you won’t be shocked by its thesis. After giving an overview of DWP Digital, Rob talks about how MongoDB and agile development are key tools to help the UK’s biggest public service department transform its data infrastructure and build a number of flagship digital services across pensions, health, benefits and analytics. Rob believes passionately that developers are the key difference between success and failure in most projects.
In the breakout sessions, Rob’s colleague David Parry got into even more detail on how DWP Digital is using agile development, Java and MongoDB in the cloud to create a microservices architecture. This architecture is making it possible to rapidly iterate from proof of concept to hundreds of services as they are rolled out nationally. Unfortunately, we couldn’t film every session, so if you would like to see this type of presentation you’ll just have to make sure you’re at MongoDB Europe later this year.
It’s been a gratifying few months getting to work so closely with the DWP Digital team. Not only are they using MongoDB in incredibly powerful ways but even more importantly I’ve gotten to see first-hand how developer-centric the organization is. You wouldn’t think of a big government department as a hotbed of developer innovation but thankfully they certainly can be. DWP Digital is proving to be every bit as forward-thinking, agile and end-user focused as the cream of Silicon Valley. And society is the better for it.
Find out more about open positions at DWP Digital on the DWP Digital Jobs Twitter account or go to careers.dwp.gov.uk. And if you’d like to know more about MongoDB’s developer focus and the events we run then follow me @jdrumgoole.
MongoDB Europe 2017 is Coming
On the 8th November 2017 we will host our premier European developer event in London, MongoDB Europe. This event is for you the developer, and like the MongoDB database, our event is designed to make your life easier in 2018 and beyond.
You might have missed a memo or two so let me get you up to speed. In 2015 we demoed Compass, our GUI for developers. In 2016, we launched MongoDB Atlas, our fully managed database service in the cloud.
This year we launched MongoDB Stitch, our Backend as a Service that combines the Atlas database with the key services a developer needs to launch applications in the cloud including authentication, file storage, third party services, and orchestration.
MongoDB Europe ‘17 is the best place to catch up on all these technologies whether you are a newbie or a seasoned veteran of the 2.x era.
MongoDB 3.6 is coming and this is the conference to find out how retryable writes, change streams, schema validation, and aggregation enhancements will simplify client side programming for MongoDB developers everywhere.
We will also have killer keynotes from Dr. Hannah Fry and James Governor.
In the morning Hannah will take you on a tour of the intriguing insights we’ve uncovered by looking at ourselves through the eyes of data and show you how a mathematical view of what it means to be human can shape the way we design our society, from dating and healthcare to catching serial killers and everything in between.
In the afternoon James will examine the trends driving grassroots-led tech adoption today, showing how convenience is always the key to success. Developers are the new Kingmakers, and the platforms that win have the shortest mean time to dopamine
Introduction: Shard N
But it gets better. For wizard level experts and above this year we are offering Shard N, so called because Shard N is the last shard in the prototypical unbound cluster.
Shard N’s talks start where the other talks end. We have some of our most technically hardcore, talented, and tenured speakers on deck. Keith Bostic, John Page, Asya Kamsky and Drew Di Palma will run extended sessions that will go deep into storage engines, distributed consensus, the aggregation framework, and our new MongoDB Stitch service.
But it’s more than just talk tracks. Come and play ping pong against your peers and get a chance to beat our CEO in a head to head match. Try out our retrogames arcade (Pacman, Asteroids, Space Invaders and more) or hang out with MongoDB staff at our beers around the world event at the end of the day.
There has never been a better time to find out about MongoDB, so be at the Intercontinental on the 8th of November and tell them ‘Joe’ sent you (use code JOE for a 25% discount off of the super low entry fee of £199).
MUGs are coming in Europe
We are planning a lot of MongoDB User Groups (MUGs) for the next few months. Eleven in total.
We will be covering schema design, the upcoming 3.6 release of MongoDB, and a host of other topics. At the Munich and London events, Amadeus, one of the world’s largest travel technology companies, handling 750m bookings every year, will be talking about their use of MongoDB.
Meetups are free and there is usually pizza and beer available. Whether you are an expert or a newbie this is a great place to catch up with other MongoDB users in your city. Click on the map below and it will take you to an interactive map browser for MUGS worldwide.
If you can’t find a meetup near your location, why not set one up? We have a complete guide. Better still, drop me a line at Joe.Drumgoole@mongodb.com and I can setup the meetup.com page for you under the MongoDB banner.
We are always looking for speakers, so if you are a MongoDB user with an interesting project that you would like to talk about contact your local Meetup Organizer. If you don’t get a response let me know and I will find a meetup for you.
We look forward to seeing you in the coming months.
Finally, don’t forget about MongoDB Europe, our annual marquee event in Europe which this year is held in London on the 8th of November. I will be an MC at the event and this year we are introducing Shard-N, a session devoted to longer, more in-depth technical talks.
MongoDB Europe - It's a Wrap!
On the 15th of November we held our first ever MongoDB Europe event. Over 1000 attendees were present for a day focussed on content for MongoDB DBAs, DevOps, and developer personnel.
Eliot Horowitz, our CTO, opened the technical sessions with a keynote on the MongoDB 3.4 release which entered into general availability on the 29th November, 2016.
Professor Brian Cox followed with the ultimate big data presentation, talking about the Big Bang and what the Sloan Digital Sky Survey can tell us about the origins of the universe. Brian’s presentation set the tone for the show, which centered on the giant ideas of MongoDB users.
We ran three “shards” – or streams of talks – throughout the day. Amazing customer sessions from Amadeus, SNCF, and Proximus, combined with highly technical talks on subjects like the Wired Tiger Storage engine, Blockchain, and how to build highly resilient MongoDB applications, all contributed to a high level of learning for all in attendance.
The show was packed all day long, with attendees mingling in the exhibition hall between talks.
We ran a ping pong ladder all day and our CEO Dev Ittycheria graciously agreed to play the winner. Dev is a bit of a demon on the ping pong table, so our ladder winner had to be content with a runner’s up prize.
We’d especially like to thank all of our Sponsors, who helped make the day so successful.
What did we learn from our first MongoDB Europe event? The feedback overall was that it was a very successful event. The one consistent stream of constructive feedback was “make it even more technical.” As long as you are up for the challenge, so are are we.
Registration is open for MongoDB World 2017:
Back to Basics: Your First MongoDB Application
We hope you enjoyed part 1 of our Back to Basics series where we introduced you to NoSQL and MongoDB.
In part II we will actually get to code and build a blogging application. We will start in the Mongo Shell to show you how to interact directly with MongoDB on the command line, then move to an IDE to show you how to build a complete web application with the MongoDB Python driver.
Once your application is built we will show you how to add indexes to improve the performance of your queries. Like most databases, indexes can dramatically improve query performance. MongoDB comes with a query analyser and a tool called Explain that can give detailed insight into query performance.
At the end of this webinar you will know how to:
- Run MongoDB
- Create a basic database and set of collections using the MongoDB Shell
- Create a basic database and collection using one of our language drivers
- Add an index to a collection to improve query performance
- Review the efficiency of your queries using the explain framework
Register now for this webinar and all the remaining webinars in the series.
Back to Basics: Learn about MongoDB in Six Easy Steps
On May 5th we will launch a new Back to Basics webinar series. The goal of this series is to provide a gentle introduction to MongoDB for people who are new to NoSQL and are interested in accelerating their own knowledge of MongoDB.
This six part series will take you from the basics of NoSQL to building and deploying your first MongoDB application.
Participants are expected to have a technical background and should have at least a basic grasp of relational database technology. Some programming experience will definitely help you to get your head around the examples.
The six webinars in the series are described below. Visit here to register for all the webinars in the series.
We start the series by taking a look at NoSQL and why you should care. We will cover the differences between the main types of NoSQL databases - document stores, wide column stores, and key value stores.
Next, we explore the details of how to build an application in MongoDB. We will cover the types of entities that we work with in a document database, as well as how to build document-based applications and how to manage performance, including the role of indexes.
In the third part of our series, we take a deeper look at the challenges of schema design. We will explore how to map relational schema into MongoDB, and how to optimize schema design for reads and writes. Finally, we’ll take a look at an interesting and unique feature of MongoDB - document validation.
One of the key value propositions of MongoDB is its advanced library of indexing techniques. In this webinar we outline how to tune indexes. We then look at our text index capabilities which allow us to do free text searching within fields in the database, and our geospatial capabilities which allow you to search based on location.
The aggregation framework is one of the most powerful analytical tools available for MongoDB. In the fifth part of our series we explore how to create a pipeline of operations that can reshape and transform your data and apply a range of analytics functions and calculations to produce summary results across a data set.
In the final talk of the series we will explain how we create a stable production environment. You will learn how to create MongoDB production deployments that can survive many different failure scenarios. You will also learn how to create a scalable cluster than can handle any increase in the production workload.
We will also introduce some of the production deployment tools that we can use to automate management and deployment.
The whole series will be recorded and made available for review by all participants. If after attending these bite sized pieces of training you want to dig deeper we recommend you look at our extensive program of free training at MongoDB University.
We look forward to seeing you online for the first episode on May 5th!
About the Author - Joe Drumgoole
Joe is Director of Developer Advocacy EMEA at MongoDB. At MongoDB he helps developers to understand and utilise MongoDB in order to unleash the power of software and data for innovators everywhere. He is a software entrepreneur with over 25 years experience of successful product delivery at Digital Equipment Corporation, Nomura, Oracle Corporation, CR2 and Cape Clear Software. He has founded three software startups. Joe is a regular speaker at technical conferences and has provided mentoring and advice to many Startups over the past ten years.