liveBook · Manning

Backward compatibility

As explained in Learn Go with Pocket-Sized Projects

Backward compatibility is the ability of a newer software version to continue working with existing users, integrations, or client code.

Backward compatibility keeps newer software working with existing users, integrations, or client code. Design public interfaces so improvements do not unnecessarily break consumers. section 4.1.1 section 10.1.1

Apply compatibility-conscious design by:

  • Keeping Protobuf field numbers permanently associated with their fields, so later versions can still recognize existing data. section 10.1.1
  • Defining dedicated request and response messages for gRPC endpoints, even when they are empty or contain one field. section 10.1.1
  • Changing private or unexported implementation details more freely while keeping exported functions, types, variables, and constants stable. section 4.1.1

Evolving a habit service

A Habit message assigns name the number 1 and weekly_frequency the number 2. Future versions can add fields without reassigning those identifiers. A CreateHabit endpoint uses CreateHabitRequest and CreateHabitResponse rather than passing Habit directly, leaving room for smaller interface changes. section 10.1.1

Listing 10.3 habit.proto: Defining the Habit message
// Habit represents an objective one wants to complete 
// a given number of times per week.
message Habit { #1
    // Name of the habit, cannot be empty
    string name = 1; #2
    // Frequency, expressed in times per week. 
    int32 weekly_frequency = 2;
}

Inspect the Habit message to see stable numeric field identifiers in a concrete Protobuf declaration. section 10.1.1

Listing 10.6 service.proto: Request and response
import "habit.proto"; #1

service Habits { 
    ... 
}

// CreateHabitRequest is the message sent to create a habit.
message CreateHabitRequest {
    // Name of the new habit. Cannot be empty.
    string name = 1;
    // Frequency of the new habit. Will default to once per week.
    optional int32 weekly_frequency = 2; #2
}

// CreateHabitResponse is the response of the create endpoint.
message CreateHabitResponse {
    Habit habit = 1;
}

Inspect dedicated request and response messages that allow a gRPC endpoint to evolve without unnecessarily breaking its API. section 10.1.1

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains stable exported symbols, Protobuf field numbers, and request-response design, but stops short of migration procedures.
Examples
Uses a numbered Habit Protobuf message, CreateHabit request and response messages, and a Go logger package.
What it assumes
Assumes familiarity with Go packages and symbols while introducing compatibility through concrete Protobuf and gRPC designs.
What you can do after
Apply it by designing stable Protobuf schemas, dedicated gRPC messages, and carefully controlled exported Go APIs.
How it connects
Connects Protobuf, gRPC, Go packages, exported symbols, APIs, and version compatibility.

Also explained in

Compare how 18 books explain backward compatibility →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.