Can this have a 2016 added to it, please?
Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
11–20 of 39 posts
Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#12Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#13so, has anyone ever pointed out that 'Schemaless' looks like how a spammer would spell 'shemales'?
Also gmail might start serving up ads for expertsexchange.com
Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#14It has some great properties. It lets you mix data with a strict schema and data without a strict schema, getting some of the benefits of both worlds.
The JSON datatype avoids many of the annoying legacy considerations that other SQL column types have. You don't have to specify a length--so you won't make a VARCHAR(255), then get burned when one day a value has more than 255 characters. You don't have specify a character encoding--JSON is always utf8mb4, the right one. (MySQL's 'utf8' encoding, perversely, supports only a subset of utf8 and will break if you try to write an emoji.)
Here's a table that illustrates some of the power:
create table unitType (
id bigint not null auto_increment,
buildingId bigint not null,
info json,
name varchar(255) as (info->>'$.name') not null,
primary key(id),
foreign key (buildingId) references building(id) on delete cascade,
unique key(buildingId, name)
);
We're modeling unit types in a building. For example, one building might contain 1-bedrooms, some nicer 1-bedrooms, and some 2-bedroom units.- It's very easy to add new fields. If, tomorrow, we decide that each unit type needs a `minSqft` and `maxSqft`, I can add them with no database migration.
- We still get most of the benefits of a schema. The database makes it impossible for a unitType to exist that does not belong to a building. The database also makes it impossible for a single building to have two unitTypes with the same name. (With a truly schemaless DB like Mongo, the complexity of preventing or dealing with those kinds of invalid data end up in the application code.)
- It makes it easy to use SQL directly, with no ORM. SQL is a powerful language; ORMs are often a leaky abstraction and a source of unessential complexity. With JSON columns for extensibility, you end up with way fewer migrations and way less need for auto-generated SQL.
- Computed columns (like name above) are really powerful.
Most of the above is possible in Postgres as well. Postgres does not have computed columns, as far as I can tell.
--
This is just to say: 99% of people on Hacker News are closer to where we are (rapid prototype phase) than where Uber is (Web ScaleTM). If that's you, consider just using JSON columns to maximize your development velocity! You can always do something fancier (like Schemaless) later on.
Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#15Still blows my mind that it took Uber so long to migrate away from a single db solution. The bit about wanting an event system to handle downstream trip processing w/o having one failure block the whole job was shocking. I’m all for avoiding premature optimization but this was taken to the extreme. PostgreSQL is capable of all of this out of the box. Wonder why a custom tool was built instead?
Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#16Naming products is demonstrably a hard problem.
Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#17FYI, MySQL has a fresh new JSON data type now. It has some great properties. It lets you mix data with a strict schema and data without a strict schema, getting some of the benefits of both worlds. The JSON datatype avoids many of the annoying legacy considerations that other SQL column types have. You don't have to specify a length--so you won't make a VARCHAR(255), then get burned when one day a value has more than…
Does MySQL not have a TEXT data type, or is it not well-supported or otherwise disadvantaged?
> It's very easy to add new fields. If, tomorrow, we decide that each unit type needs a `minSqft` and `maxSqft`, I can add them with no database migration.
TBF, column-adding being a pain is really a MySQL-specific problem.
> It makes it easy to use SQL directly, with no ORM. SQL is a powerful language; ORMs are often a leaky abstraction and a source of unessential complexity. With JSON columns for extensibility, you end up with way fewer migrations and way less need for auto-generated SQL.
ORMs being a "leaky abstraction" is a good thing; good ORMs are not too far removed from SQL precisely because they're leaky.
Pushing schema management to the app layer (as opposed to migrations) is also a source for "unnecessary complexity".
Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#18Still blows my mind that it took Uber so long to migrate away from a single db solution. The bit about wanting an event system to handle downstream trip processing w/o having one failure block the whole job was shocking. I’m all for avoiding premature optimization but this was taken to the extreme. PostgreSQL is capable of all of this out of the box. Wonder why a custom tool was built instead?
I'm pretty sure they've seen a few iterations on their data stores. I remember attending a meetup at Urban Airship in 2012 or so where Uber engineers gave a presentation about a data store migration (I think from Mongo to MySQL)
Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#19Re: Designing Schemaless, Uber Engineering’s Scalable Datastore Using MySQL (2016)
#20FYI, MySQL has a fresh new JSON data type now. It has some great properties. It lets you mix data with a strict schema and data without a strict schema, getting some of the benefits of both worlds. The JSON datatype avoids many of the annoying legacy considerations that other SQL column types have. You don't have to specify a length--so you won't make a VARCHAR(255), then get burned when one day a value has more than…
> You don't have to specify a length--so you won't make a VARCHAR(255), then get burned when one day a value has more than 255 characters. Does MySQL not have a TEXT data type, or is it not well-supported or otherwise disadvantaged? > It's very easy to add new fields. If, tomorrow, we decide that each unit type needs a `minSqft` and `maxSqft`, I can add them with no database migration. TBF, column-adding being a pain…
It does, but it's still length limited--more precisely, there are several different TEXT data types, with different length limits. This bit me recently on a project, where I was sending strings over the length limit to a TEXT field and wondered why they got truncated until I read the spec more carefully.