Integrating with the MoviesService
Because we’ve ripped our application in two, we need some way to
link the data in the two applications back together. I’ve already
alluded to the idea that a MovieShowtime object is the “product” of the
MoviesService, and that the MoviesService needs to obtain and track
product ids returned from the OrdersService. To accomplish this, we need to
add a product_id column to the
movie_showtimes table, as shown in
Example 16-10. Note that
the column type is text, rather than
integer. Just as OrdersService strives to maintain independence
from its clients, so too should clients add a layer of abstraction
between themselves and the services they consume. Although the product
ids are integers today, they might not be forever.
Since there is no explicit reference to maintain within the movies
database, the schema can be built to be generic enough to support
today’s as well as tomorrow’s needs.
Example 16-10. Modifications to the movie_showtimes table to support an orders service
create table movie_showtimes (
id integer not null
default nextval('movie_showtimes_id_seq'),
movie_id integer not null
references movies(id),
theatre_id integer not null
references theatres(id),
room varchar(64) not null,
start_time timestamp with time zone not null,
primary key (id),
product_id text,
unique(movie_id, theatre_id, room, start_time),
foreign key (theatre_id, room)
references auditoriums(theatre_id, room) initially deferred
);We also need to instrument the registration ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access