Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Interface Design for Spark Community

Reynold Xin
January 27, 2015

Interface Design for Spark Community

In Spark, we have done reasonable well historically in interface and API design, especially compared with some other Big Data systems. However, we have also made mistakes along the way. I want to share a talk I gave about interface design at Databricks' internal retreat.

Interface design is a vital part of Spark becoming a long-term sustainable, thriving framework. Good interfaces can be the project's biggest asset, while bad interfaces can be the worst technical debt. As the project scales bigger and bigger, the community is expanding and we are getting a wider range of contributors that have not thought about this as their everyday development experience outside Spark.

It is part-art part-science and in some sense acquired taste. However, I think there are common issues that can be spotted easily, and common principles that can address a lot of the low hanging fruits. Through this presentation, I hope to bring to everybody's attention the issue of interface design and encourage everybody to think hard about interface design in their contributions.

Reynold Xin

January 27, 2015
Tweet

More Decks by Reynold Xin

Other Decks in Programming

Transcript

  1. Spark’s two improvements over Hadoop MR • Performance: “100X” faster

    than Hadoop MR • Programming model: easier to use
  2. public static class WordCountMapClass extends MapReduceBase implements Mapper<LongWritable, Text, Text,

    IntWritable> { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { String line = value.toString(); StringTokenizer itr = new StringTokenizer(line); while (itr.hasMoreTokens()) { word.set(itr.nextToken()); output.collect(word, one); } } } public static class WorkdCountReduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> { public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { int sum = 0; while (values.hasNext()) { sum += values.next().get(); } output.collect(key, new IntWritable(sum)); } } import org.apache.spark.SparkContext import org.apache.spark.SparkContext._ val spark = new SparkContext(master, appName, [sparkHome], [jars]) val file = spark.textFile("hdfs://...") val counts = file.flatMap(line => line.split(" ")) .map(word => (word, 1)) .reduceByKey(_ + _) counts.saveAsTextFile("hdfs://...") Hadoop MR Spark “It has been the easiest learning experience that I went through” - Burak coerced by Reynold
  3. • Undergrad CS education cares more about implementation of functionality

    • PhD research cares more about prototyping and validating ideas • Neither requires thinking hard about interface design
  4. – Damian Conway on “Ten Essential Development Practices" “The most

    important aspect of any module is not how it implements the facilities it provides, but the way in which it provides those facilities in the first place.”
  5. Example of Interfaces • public programming APIs (e.g. RDD) •

    external modules we expose (matplotlib) • default imports in notebooks • internal module methods (e.g. tree store) • command line arguments • configuration options
  6. Why is interface design important? • If you write code,

    you are already doing design • Interfaces can be our biggest asset • or biggest liabilities!
  7. Public Interfaces as Assets • Great public interfaces capture emotions

    and in turn capture customers • Customers invest heavily in (public) interfaces • Cost of switching interfaces is HIGH: rewriting & retraining • Network effect: each “customer” brings value to another by writing apps and talking about it
  8. Internal Interfaces as Assets • Great internal interfaces capture emotions

    and in turn capture developers • Developers reinforce our leadership • Well designed internal interfaces enable us to move faster • e.g. compression codec vs connection manager
  9. Interfaces as Liabilities • Bad public interfaces increase support burden

    • groupByKey anyone? • Bad internal interfaces increase cost of maintenance and innovation
  10. Good Interfaces • Easy to learn & use • Sufficiently

    powerful • Anticipating an inability to know future needs • Backward compatible
  11. Process 1. Identify modules: separation of concerns 2. For each

    module: don’t sweat implementation details but take time to identify interfaces, minimize them, and think how they evolve 3. Design, prototype & program using the interfaces 4. Write out a short design doc and ask for feedback 5. Implement the interface, and re-iterate
  12. Keep it simple, stupid (KISS) • Easier to learn /

    use • Easier to document • Easier to implement (less bugs) • Easier to optimize narrow interfaces • Easier to throw out / re-implement • Easier to support long term
  13. Ways to Simply Design Remove: Get rid of anything that

    isn’t essential to the application. This could mean content, too; like the language you use in the navigation labels. Organize: Arrange the elements of the interface so that they fit into logical chunks. This might mean based on a person’s mental model (how they think), or tie in to a more familiar interface pattern. Hide: Place the most important elements within reach (make them obvious), and hide the others, making them accessible through navigation. Displace: Pushing some of the functionality to another device, or feature, so that the one interface isn’t responsible for displaying every possible interaction.
  14. Name Matters • Class, variable, method names should be self-

    explanatory • Avoid cryptic names (e.g. operator overloading) • Be consistent
  15. ExecutorLauncher yarn-client ExecutorRunner standalone DriverRunner standalone DriverWrapper standalone Client standalone

    Client (another one) yarn Client Base yarn AppClient standalone Bad Examples in Spark
  16. Minimize Accessibility • Make classes and members as private as

    possible, even for internal modules • This maximizes information hiding • Enables modules to be used, understood, built, tested, and debugged independently • A bad habit of many Scala developers to leave everything wide open
  17. Principle of least astonishment • Use your common sense; interfaces

    should not surprise users • e.g. Tachyon format command accidentally deletes file
  18. Long-term Maintainability • When in doubt, leave it out •

    Every interface added increases complexity • Easier to add than remove in the future • Avoid exposing dependency on 3rd party libraries • e.g. MLlib’s use of Breeze (+) • e.g. Spark’s use of Guava Optional (-) • Don’t let implementation details impact interface design
  19. • KISS • Remove, hide, organize, displace • Name matters

    • Documentations matter • Minimize accessibility • Compose interfaces for expressivity • Long-term maintainability • …
  20. Interface Design • Years of effort; impossible to do overnight

    • Critical in building out a strong platform • Critical in ensuring the long-term pace of innovation • We scored better than anybody else out there, but still a long way to go
  21. References • Eric S. Raymond, Basics of the Unix Philosophy

    http://www.faqs.org/docs/artu/ch01s06.html • Joshua Bloch, How to Design a Good API and Why it Matters http://lcsd05.cs.tamu.edu/slides/ keynote.pdf • Richard Gabriel, The Rise of ``Worse is Better’’ http://www.jwz.org/doc/worse-is-better.html (I don’t actually agree with the article)